Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
36.21% |
926 / 2557 |
|
10.00% |
5 / 50 |
CRAP | |
0.00% |
0 / 1 |
| AppController | |
36.14% |
923 / 2554 |
|
10.00% |
5 / 50 |
199813.98 | |
0.00% |
0 / 1 |
| processSGF | |
98.11% |
52 / 53 |
|
0.00% |
0 / 1 |
15 | |||
| xFlip | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| yFlip | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| getInitialPositionEnd | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| getInitialPosition | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
6 | |||
| getInvisibleSets | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| getDeletedSets | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| startPageUpdate | |
88.89% |
16 / 18 |
|
0.00% |
0 / 1 |
5.03 | |||
| uotd | |
0.00% |
0 / 157 |
|
0.00% |
0 / 1 |
2070 | |||
| deleteUnusedStatuses | |
0.00% |
0 / 40 |
|
0.00% |
0 / 1 |
72 | |||
| saveSolvedNumber | |
78.12% |
25 / 32 |
|
0.00% |
0 / 1 |
13.51 | |||
| resetUserElos | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
| handleContribution | |
52.94% |
9 / 17 |
|
0.00% |
0 / 1 |
2.42 | |||
| getAllTags | |
96.55% |
28 / 29 |
|
0.00% |
0 / 1 |
7 | |||
| deleteUserBoards | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getNewTsumego | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
| publishSingle | |
0.00% |
0 / 45 |
|
0.00% |
0 / 1 |
30 | |||
| getTsumegoOfTheDay | |
0.00% |
0 / 104 |
|
0.00% |
0 / 1 |
1190 | |||
| ratingMatch | |
0.00% |
0 / 62 |
|
0.00% |
0 / 1 |
992 | |||
| rating2 | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
132 | |||
| encrypt | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| decrypt | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| checkPictureLarge | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| checkPicture | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
3.33 | |||
| getTsumegoRankx | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
506 | |||
| adjustElo | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
132 | |||
| getTsumegoElo | |
60.38% |
32 / 53 |
|
0.00% |
0 / 1 |
95.70 | |||
| getTsumegoRankVal | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
506 | |||
| getTsumegoRankMax | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
506 | |||
| saveDanSolveCondition | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
7 | |||
| updateSprintCondition | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
4.00 | |||
| updateGoldenCondition | |
94.12% |
16 / 17 |
|
0.00% |
0 / 1 |
3.00 | |||
| setPotionCondition | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
| updateGems | |
3.85% |
4 / 104 |
|
0.00% |
0 / 1 |
2183.48 | |||
| checkProblemNumberAchievements | |
42.39% |
39 / 92 |
|
0.00% |
0 / 1 |
166.38 | |||
| checkDanSolveAchievements | |
46.82% |
81 / 173 |
|
0.00% |
0 / 1 |
545.62 | |||
| checkForLocked | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
| checkNoErrorAchievements | |
50.77% |
33 / 65 |
|
0.00% |
0 / 1 |
51.48 | |||
| checkTimeModeAchievements | |
35.40% |
40 / 113 |
|
0.00% |
0 / 1 |
2273.83 | |||
| checkRatingAchievements | |
54.44% |
49 / 90 |
|
0.00% |
0 / 1 |
95.92 | |||
| checkLevelAchievements | |
72.22% |
65 / 90 |
|
0.00% |
0 / 1 |
42.63 | |||
| checkSetCompletedAchievements | |
19.72% |
14 / 71 |
|
0.00% |
0 / 1 |
166.54 | |||
| setAchievementSpecial | |
0.00% |
0 / 184 |
|
0.00% |
0 / 1 |
4160 | |||
| checkSetAchievements | |
18.10% |
40 / 221 |
|
0.00% |
0 / 1 |
2533.09 | |||
| getXPJump | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
72 | |||
| updateXP | |
60.00% |
6 / 10 |
|
0.00% |
0 / 1 |
3.58 | |||
| getPartitionRange | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
56 | |||
| handleSearchSettings | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |||
| signIn | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
2.02 | |||
| beforeFilter | |
83.28% |
279 / 335 |
|
0.00% |
0 / 1 |
94.55 | |||
| afterFilter | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| 1 | <?php |
| 2 | |
| 3 | App::uses('Auth', 'Utility'); |
| 4 | App::uses('TsumegoFilters', 'Utility'); |
| 5 | App::uses('TimeMode', 'Utility'); |
| 6 | |
| 7 | class AppController extends Controller { |
| 8 | public $viewClass = 'App'; |
| 9 | |
| 10 | public $components = [ |
| 11 | 'Session', |
| 12 | //'DebugKit.Toolbar', |
| 13 | 'Flash', |
| 14 | 'PlayResultProcessor' |
| 15 | ]; |
| 16 | |
| 17 | public static function processSGF($sgf) { |
| 18 | $aw = strpos($sgf, 'AW'); |
| 19 | $ab = strpos($sgf, 'AB'); |
| 20 | $boardSizePos = strpos($sgf, 'SZ'); |
| 21 | $boardSize = 19; |
| 22 | $sgfArr = str_split($sgf); |
| 23 | if ($boardSizePos !== false) { |
| 24 | $boardSize = $sgfArr[$boardSizePos + 3] . '' . $sgfArr[$boardSizePos + 4]; |
| 25 | } |
| 26 | if (substr($boardSize, 1) == ']') { |
| 27 | $boardSize = substr($boardSize, 0, 1); |
| 28 | } |
| 29 | |
| 30 | $black = AppController::getInitialPosition($ab, $sgfArr, 'x'); |
| 31 | $white = AppController::getInitialPosition($aw, $sgfArr, 'o'); |
| 32 | $stones = array_merge($black, $white); |
| 33 | |
| 34 | $board = []; |
| 35 | for ($i = 0; $i < 19; $i++) { |
| 36 | $board[$i] = []; |
| 37 | for ($j = 0; $j < 19; $j++) { |
| 38 | $board[$i][$j] = '-'; |
| 39 | } |
| 40 | } |
| 41 | $lowestX = 18; |
| 42 | $lowestY = 18; |
| 43 | $highestX = 0; |
| 44 | $highestY = 0; |
| 45 | $stonesCount = count($stones); |
| 46 | for ($i = 0; $i < $stonesCount; $i++) { |
| 47 | if ($stones[$i][0] < $lowestX) { |
| 48 | $lowestX = $stones[$i][0]; |
| 49 | } |
| 50 | if ($stones[$i][0] > $highestX) { |
| 51 | $highestX = $stones[$i][0]; |
| 52 | } |
| 53 | if ($stones[$i][1] < $lowestY) { |
| 54 | $lowestY = $stones[$i][1]; |
| 55 | } |
| 56 | if ($stones[$i][1] > $highestY) { |
| 57 | $highestY = $stones[$i][1]; |
| 58 | } |
| 59 | } |
| 60 | if (18 - $lowestX < $lowestX) { |
| 61 | $stones = AppController::xFlip($stones); |
| 62 | } |
| 63 | if (18 - $lowestY < $lowestY) { |
| 64 | $stones = AppController::yFlip($stones); |
| 65 | } |
| 66 | $highestX = 0; |
| 67 | $highestY = 0; |
| 68 | $stonesCount = count($stones); |
| 69 | for ($i = 0; $i < $stonesCount; $i++) { |
| 70 | if ($stones[$i][0] > $highestX) { |
| 71 | $highestX = $stones[$i][0]; |
| 72 | } |
| 73 | if ($stones[$i][1] > $highestY) { |
| 74 | $highestY = $stones[$i][1]; |
| 75 | } |
| 76 | $board[$stones[$i][0]][$stones[$i][1]] = $stones[$i][2]; |
| 77 | } |
| 78 | $tInfo = []; |
| 79 | $tInfo[0] = $highestX; |
| 80 | $tInfo[1] = $highestY; |
| 81 | $arr = []; |
| 82 | $arr[0] = $board; |
| 83 | $arr[1] = $stones; |
| 84 | $arr[2] = $tInfo; |
| 85 | $arr[3] = $boardSize; |
| 86 | |
| 87 | return $arr; |
| 88 | } |
| 89 | |
| 90 | public static function xFlip($stones) { |
| 91 | $stonesCount = count($stones); |
| 92 | for ($i = 0; $i < $stonesCount; $i++) { |
| 93 | $stones[$i][0] = 18 - $stones[$i][0]; |
| 94 | } |
| 95 | |
| 96 | return $stones; |
| 97 | } |
| 98 | |
| 99 | public static function yFlip($stones) { |
| 100 | $stonesCount = count($stones); |
| 101 | for ($i = 0; $i < $stonesCount; $i++) { |
| 102 | $stones[$i][1] = 18 - $stones[$i][1]; |
| 103 | } |
| 104 | |
| 105 | return $stones; |
| 106 | } |
| 107 | |
| 108 | public static function getInitialPositionEnd($pos, $sgfArr) { |
| 109 | $endCondition = 0; |
| 110 | $currentPos1 = $pos + 2; |
| 111 | $currentPos2 = $pos + 5; |
| 112 | while ($sgfArr[$currentPos1] == '[' && $sgfArr[$currentPos2] == ']') { |
| 113 | $endCondition = $currentPos2; |
| 114 | $currentPos1 += 4; |
| 115 | $currentPos2 += 4; |
| 116 | } |
| 117 | |
| 118 | return $endCondition; |
| 119 | } |
| 120 | |
| 121 | public static function getInitialPosition($pos, $sgfArr, $color) { |
| 122 | $arr = []; |
| 123 | $end = AppController::getInitialPositionEnd($pos, $sgfArr); |
| 124 | for ($i = $pos + 2; $i < $end; $i++) { |
| 125 | if ($sgfArr[$i] != '[' && $sgfArr[$i] != ']') { |
| 126 | array_push($arr, strtolower($sgfArr[$i])); |
| 127 | } |
| 128 | } |
| 129 | $alphabet = array_flip(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']); |
| 130 | $xy = true; |
| 131 | $arr2 = []; |
| 132 | $c = 0; |
| 133 | $arrCount = count($arr); |
| 134 | for ($i = 0; $i < $arrCount; $i++) { |
| 135 | $arr[$i] = $alphabet[$arr[$i]]; |
| 136 | if ($xy) { |
| 137 | $arr2[$c] = []; |
| 138 | $arr2[$c][0] = $arr[$i]; |
| 139 | } else { |
| 140 | $arr2[$c][1] = $arr[$i]; |
| 141 | $arr2[$c][2] = $color; |
| 142 | $c++; |
| 143 | } |
| 144 | $xy = !$xy; |
| 145 | } |
| 146 | |
| 147 | return $arr2; |
| 148 | } |
| 149 | |
| 150 | protected function getInvisibleSets() { |
| 151 | $this->loadModel('Set'); |
| 152 | $invisibleSets = []; |
| 153 | $in = $this->Set->find('all', ['conditions' => ['public' => 0]]); |
| 154 | if (!$in) { |
| 155 | $in = []; |
| 156 | } |
| 157 | foreach ($in as $item) { |
| 158 | $invisibleSets[] = $item['Set']['id']; |
| 159 | } |
| 160 | |
| 161 | return $invisibleSets; |
| 162 | } |
| 163 | |
| 164 | protected function getDeletedSets() { |
| 165 | $dSets = []; |
| 166 | $de = $this->Set->find('all', ['conditions' => ['public' => -1]]); |
| 167 | if (!$de) { |
| 168 | $de = []; |
| 169 | } |
| 170 | foreach ($de as $item) { |
| 171 | $dSets[] = $item['Set']['id']; |
| 172 | } |
| 173 | |
| 174 | return $dSets; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * @return void |
| 179 | */ |
| 180 | public static function startPageUpdate() { |
| 181 | $str = ''; |
| 182 | $latest = ClassRegistry::init('AchievementStatus')->find('all', ['limit' => 7, 'order' => 'created DESC']); |
| 183 | if (!$latest) { |
| 184 | $latest = []; |
| 185 | } |
| 186 | $latestCount = count($latest); |
| 187 | for ($i = 0; $i < $latestCount; $i++) { |
| 188 | $a = ClassRegistry::init('Achievement')->findById($latest[$i]['AchievementStatus']['achievement_id']); |
| 189 | $u = ClassRegistry::init('User')->findById($latest[$i]['AchievementStatus']['user_id']); |
| 190 | if (substr($u['User']['name'], 0, 3) == 'g__' && $u['User']['external_id'] != null) { |
| 191 | $startPageUser = AppController::checkPicture($u); |
| 192 | } else { |
| 193 | $startPageUser = $u['User']['name']; |
| 194 | } |
| 195 | $latest[$i]['AchievementStatus']['name'] = $a['Achievement']['name']; |
| 196 | $latest[$i]['AchievementStatus']['color'] = $a['Achievement']['color']; |
| 197 | $latest[$i]['AchievementStatus']['image'] = $a['Achievement']['image']; |
| 198 | $latest[$i]['AchievementStatus']['user'] = $startPageUser; |
| 199 | $str .= '<div class="quote1"><div class="quote1a"><a href="/achievements/view/' . $a['Achievement']['id'] . '"><img src="/img/' . $a['Achievement']['image'] . '.png" width="34px"></a></div>'; |
| 200 | $str .= '<div class="quote1b">Achievement gained by ' . $startPageUser . ':<br><div class=""><b>' . $a['Achievement']['name'] . '</b></div></div></div>'; |
| 201 | } |
| 202 | file_put_contents('mainPageAjax.txt', $str); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * @return void |
| 207 | */ |
| 208 | protected function uotd() { //routine1 |
| 209 | $this->loadModel('User'); |
| 210 | $this->loadModel('DayRecord'); |
| 211 | $this->loadModel('TsumegoAttempt'); |
| 212 | $this->loadModel('Achievement'); |
| 213 | $this->loadModel('AchievementCondition'); |
| 214 | $today = date('Y-m-d'); |
| 215 | $ux2 = $this->User->find('all', [ |
| 216 | 'limit' => '8', |
| 217 | 'order' => 'reuse3 DESC', |
| 218 | 'conditions' => [ |
| 219 | 'NOT' => ['id' => [33]], |
| 220 | ], |
| 221 | ]); |
| 222 | if (!$ux2) { |
| 223 | $ux2 = []; |
| 224 | } |
| 225 | $last = $this->DayRecord->find('all', ['limit' => '7', 'order' => 'date DESC']); |
| 226 | if (!$last) { |
| 227 | $last = []; |
| 228 | } |
| 229 | $lastUotds = []; |
| 230 | $lastUsers = []; |
| 231 | foreach ($last as $item) { |
| 232 | $lastUotds[] = $item['DayRecord']['user_id']; |
| 233 | } |
| 234 | foreach ($ux2 as $item) { |
| 235 | $lastUsers[] = $item['User']['id']; |
| 236 | } |
| 237 | $resultUser = 72; |
| 238 | $lastUsersCount = count($lastUsers); |
| 239 | for ($i = 0; $i < $lastUsersCount; $i++) { |
| 240 | $foundUser = false; |
| 241 | $lastUotdsCount = count($lastUotds); |
| 242 | for ($j = 0; $j < $lastUotdsCount; $j++) { |
| 243 | if ($lastUsers[$i] == $lastUotds[$j]) { |
| 244 | $foundUser = true; |
| 245 | } |
| 246 | } |
| 247 | if (!$foundUser) { |
| 248 | $resultUser = $lastUsers[$i]; |
| 249 | |
| 250 | break; |
| 251 | } |
| 252 | } |
| 253 | $ux = $this->User->findById($resultUser); |
| 254 | |
| 255 | $recentlyUsed = []; |
| 256 | $d = 1; |
| 257 | while ($d <= 10) { |
| 258 | $ru = $this->DayRecord->find('first', ['conditions' => ['date' => date('Y-m-d', strtotime('-' . $d . ' days'))]]); |
| 259 | if ($ru) { |
| 260 | array_push($recentlyUsed, $ru); |
| 261 | } |
| 262 | $d++; |
| 263 | } |
| 264 | $currentQuote = 'q01'; |
| 265 | $newQuote = 'q01'; |
| 266 | $quoteChosen = false; |
| 267 | while (!$quoteChosen) { |
| 268 | $newQuote = rand(1, 45); |
| 269 | if ($newQuote < 10) { |
| 270 | $newQuote = 'q0' . $newQuote; |
| 271 | } else { |
| 272 | $newQuote = 'q' . $newQuote; |
| 273 | } |
| 274 | |
| 275 | $f = false; |
| 276 | $recentlyUsedCount = count($recentlyUsed); |
| 277 | for ($i = 0; $i < $recentlyUsedCount; $i++) { |
| 278 | if ($newQuote == $recentlyUsed[$i]['DayRecord']['quote']) { |
| 279 | $f = true; |
| 280 | } |
| 281 | } |
| 282 | if (!$f) { |
| 283 | $quoteChosen = true; |
| 284 | } |
| 285 | } |
| 286 | $currentQuote = $newQuote; |
| 287 | $dayUserRand = 1; |
| 288 | $uotdChosen = false; |
| 289 | while (!$uotdChosen) { |
| 290 | $dayUserRand = rand(1, 39); |
| 291 | $f = false; |
| 292 | $recentlyUsedCount = count($recentlyUsed); |
| 293 | for ($i = 0; $i < $recentlyUsedCount; $i++) { |
| 294 | if ($dayUserRand == $recentlyUsed[$i]['DayRecord']['userbg']) { |
| 295 | $f = true; |
| 296 | } |
| 297 | } |
| 298 | if (!$f) { |
| 299 | $uotdChosen = true; |
| 300 | } |
| 301 | } |
| 302 | $activity = $this->TsumegoAttempt->find('all', ['limit' => 40000, 'conditions' => ['DATE(TsumegoAttempt.updated)' => date('Y-m-d', strtotime('yesterday'))]]); |
| 303 | if (!$activity) { |
| 304 | $activity = []; |
| 305 | } |
| 306 | $visitedProblems = count($activity); |
| 307 | |
| 308 | //how many users today |
| 309 | $usersNum = []; |
| 310 | $activity = $this->User->find('all', ['limit' => 400, 'order' => 'created DESC']); |
| 311 | if (!$activity) { |
| 312 | $activity = []; |
| 313 | } |
| 314 | $activityCount = count($activity); |
| 315 | for ($i = 0; $i < $activityCount; $i++) { |
| 316 | $a = new DateTime($activity[$i]['User']['created']); |
| 317 | if ($a->format('Y-m-d') == $today) { |
| 318 | array_push($usersNum, $activity[$i]['User']); |
| 319 | } |
| 320 | } |
| 321 | $gemRand1 = rand(0, 2); |
| 322 | $gemRand2 = rand(0, 2); |
| 323 | $gemRand3 = rand(0, 2); |
| 324 | |
| 325 | $arch1 = ClassRegistry::init('Achievement')->findById(111); |
| 326 | if ($gemRand1 == 0) { |
| 327 | $arch1['Achievement']['description'] = 'Has a chance to trigger once a day on an easy ddk problem.'; |
| 328 | } elseif ($gemRand1 == 1) { |
| 329 | $arch1['Achievement']['description'] = 'Has a chance to trigger once a day on a regular ddk problem.'; |
| 330 | } elseif ($gemRand1 == 2) { |
| 331 | $arch1['Achievement']['description'] = 'Has a chance to trigger once a day on a difficult ddk problem.'; |
| 332 | } |
| 333 | ClassRegistry::init('Achievement')->save($arch1); |
| 334 | $arch2 = ClassRegistry::init('Achievement')->findById(112); |
| 335 | if ($gemRand2 == 0) { |
| 336 | $arch2['Achievement']['description'] = 'Has a chance to trigger once a day on an easy sdk problem.'; |
| 337 | } elseif ($gemRand2 == 1) { |
| 338 | $arch2['Achievement']['description'] = 'Has a chance to trigger once a day on a regular sdk problem.'; |
| 339 | } elseif ($gemRand2 == 2) { |
| 340 | $arch2['Achievement']['description'] = 'Has a chance to trigger once a day on a difficult sdk problem.'; |
| 341 | } |
| 342 | ClassRegistry::init('Achievement')->save($arch2); |
| 343 | $arch3 = ClassRegistry::init('Achievement')->findById(113); |
| 344 | if ($gemRand3 == 0) { |
| 345 | $arch3['Achievement']['description'] = 'Has a chance to trigger once a day on an easy dan problem.'; |
| 346 | } elseif ($gemRand3 == 1) { |
| 347 | $arch3['Achievement']['description'] = 'Has a chance to trigger once a day on a regular dan problem.'; |
| 348 | } elseif ($gemRand3 == 2) { |
| 349 | $arch3['Achievement']['description'] = 'Has a chance to trigger once a day on a difficult dan problem.'; |
| 350 | } |
| 351 | ClassRegistry::init('Achievement')->save($arch3); |
| 352 | |
| 353 | $this->DayRecord->create(); |
| 354 | $dateUser = []; |
| 355 | $dateUser['DayRecord']['user_id'] = $ux['User']['id']; |
| 356 | $dateUser['DayRecord']['date'] = $today; |
| 357 | $dateUser['DayRecord']['solved'] = $ux['User']['reuse3']; |
| 358 | $dateUser['DayRecord']['quote'] = $currentQuote; |
| 359 | $dateUser['DayRecord']['userbg'] = $dayUserRand; |
| 360 | $dateUser['DayRecord']['tsumego'] = $this->getTsumegoOfTheDay(); |
| 361 | $dateUser['DayRecord']['newTsumego'] = $this->getNewTsumego(); |
| 362 | $dateUser['DayRecord']['usercount'] = count($usersNum); |
| 363 | $dateUser['DayRecord']['visitedproblems'] = $visitedProblems; |
| 364 | $dateUser['DayRecord']['gems'] = $gemRand1 . '-' . $gemRand2 . '-' . $gemRand3; |
| 365 | $dateUser['DayRecord']['gemCounter1'] = 0; |
| 366 | $dateUser['DayRecord']['gemCounter2'] = 0; |
| 367 | $dateUser['DayRecord']['gemCounter3'] = 0; |
| 368 | $this->DayRecord->save($dateUser); |
| 369 | |
| 370 | ClassRegistry::init('AchievementCondition')->create(); |
| 371 | $achievementCondition = []; |
| 372 | $achievementCondition['AchievementCondition']['user_id'] = $ux['User']['id']; |
| 373 | $achievementCondition['AchievementCondition']['set_id'] = 0; |
| 374 | $achievementCondition['AchievementCondition']['category'] = 'uotd'; |
| 375 | $achievementCondition['AchievementCondition']['value'] = 1; |
| 376 | ClassRegistry::init('AchievementCondition')->save($achievementCondition); |
| 377 | |
| 378 | //delete duplicated DayRecords |
| 379 | $dr = $this->DayRecord->find('all'); |
| 380 | if (!$dr) { |
| 381 | $dr = []; |
| 382 | } |
| 383 | $duplicates = []; |
| 384 | $drCount = count($dr); |
| 385 | for ($i = 0; $i < $drCount; $i++) { |
| 386 | $alreadyFound = []; |
| 387 | for ($j = 0; $j < $drCount; $j++) { |
| 388 | if ($i != $j && $dr[$j]['DayRecord']['date'] == $dr[$i]['DayRecord']['date']) { |
| 389 | $found = false; |
| 390 | $alreadyFoundCount = count($alreadyFound); |
| 391 | for ($k = 0; $k < $alreadyFoundCount; $k++) { |
| 392 | if ($alreadyFound[$k]['DayRecord']['id'] == $dr[$i]['DayRecord']['id'] || $alreadyFound[$k]['DayRecord']['id'] == $dr[$j]['DayRecord']['id']) { |
| 393 | $found = true; |
| 394 | } |
| 395 | } |
| 396 | if (!$found) { |
| 397 | array_push($duplicates, $dr[$i]['DayRecord']['date']); |
| 398 | array_push($alreadyFound, $dr[$i]); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | $duplicates = array_count_values($duplicates); |
| 404 | foreach ($duplicates as $key => $value) { |
| 405 | while ($duplicates[$key] > 1) { |
| 406 | $drd = $this->DayRecord->find('first', ['conditions' => ['date' => $key]]); |
| 407 | if ($drd) { |
| 408 | $this->DayRecord->delete($drd['DayRecord']['id']); |
| 409 | } |
| 410 | $duplicates[$key]--; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | public static function deleteUnusedStatuses(int $uid): void { |
| 416 | $s = ClassRegistry::init('Set')->find('all', [ |
| 417 | 'conditions' => [ |
| 418 | 'OR' => [ |
| 419 | ['public' => 1], |
| 420 | ['public' => 0], |
| 421 | ], |
| 422 | ], |
| 423 | ]) ?: []; |
| 424 | $ids = []; |
| 425 | $sCount = count($s); |
| 426 | for ($i = 0; $i < $sCount; $i++) { |
| 427 | $tSet = TsumegoUtil::collectTsumegosFromSet($s[$i]['Set']['id']); |
| 428 | foreach ($tSet as $item) { |
| 429 | $ids[] = $item['Tsumego']['id']; |
| 430 | } |
| 431 | } |
| 432 | $ut = ClassRegistry::init('TsumegoStatus')->find('all', [ |
| 433 | 'conditions' => [ |
| 434 | 'user_id' => $uid, |
| 435 | 'NOT' => [ |
| 436 | 'tsumego_id' => $ids, |
| 437 | ], |
| 438 | ], |
| 439 | ]); |
| 440 | if (!$ut) { |
| 441 | $ut = []; |
| 442 | } |
| 443 | $utCount = count($ut); |
| 444 | for ($i = 0; $i < $utCount; $i++) { |
| 445 | $test1 = ClassRegistry::init('Tsumego')->findById($ut[$i]['TsumegoStatus']['tsumego_id']); |
| 446 | $test2 = ClassRegistry::init('SetConnection')->find('first', ['conditions' => ['tsumego_id' => $test1['Tsumego']['id']]]); |
| 447 | if (!$test2) { |
| 448 | ClassRegistry::init('TsumegoStatus')->delete($ut[$i]['TsumegoStatus']['id']); |
| 449 | |
| 450 | continue; |
| 451 | } |
| 452 | $test3 = ClassRegistry::init('Set')->find('first', [ |
| 453 | 'id' => $test2['SetConnection']['set_id'], |
| 454 | 'OR' => [ |
| 455 | ['public' => 1], |
| 456 | ['public' => 0], |
| 457 | ], |
| 458 | ]); |
| 459 | if ($test3 == null) { |
| 460 | ClassRegistry::init('TsumegoStatus')->delete($ut[$i]['TsumegoStatus']['id']); |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | protected function saveSolvedNumber($uid) { |
| 466 | $this->loadModel('User'); |
| 467 | $this->loadModel('TsumegoStatus'); |
| 468 | $this->loadModel('Set'); |
| 469 | $this->loadModel('SetConnection'); |
| 470 | |
| 471 | $solvedUts2 = 0; |
| 472 | $tsumegos = $this->SetConnection->find('all'); |
| 473 | if (!$tsumegos) { |
| 474 | $tsumegos = []; |
| 475 | } |
| 476 | $uts = $this->TsumegoStatus->find('all', ['order' => 'updated DESC', 'conditions' => ['user_id' => $uid]]); |
| 477 | if (!$uts) { |
| 478 | $uts = []; |
| 479 | } |
| 480 | $setKeys = []; |
| 481 | $setArray = $this->Set->find('all', ['conditions' => ['public' => 1]]); |
| 482 | if (!$setArray) { |
| 483 | $setArray = []; |
| 484 | } |
| 485 | |
| 486 | $setArrayCount = count($setArray); |
| 487 | for ($i = 0; $i < $setArrayCount; $i++) { |
| 488 | $setKeys[$setArray[$i]['Set']['id']] = $setArray[$i]['Set']['id']; |
| 489 | } |
| 490 | |
| 491 | $scs = []; |
| 492 | $tsumegosCount = count($tsumegos); |
| 493 | for ($j = 0; $j < $tsumegosCount; $j++) { |
| 494 | if (!isset($scs[$tsumegos[$j]['SetConnection']['tsumego_id']])) { |
| 495 | $scs[$tsumegos[$j]['SetConnection']['tsumego_id']] = 1; |
| 496 | } else { |
| 497 | $scs[$tsumegos[$j]['SetConnection']['tsumego_id']]++; |
| 498 | } |
| 499 | } |
| 500 | $utsCount = count($uts); |
| 501 | for ($j = 0; $j < $utsCount; $j++) { |
| 502 | if ($uts[$j]['TsumegoStatus']['status'] == 'S' || $uts[$j]['TsumegoStatus']['status'] == 'W' || $uts[$j]['TsumegoStatus']['status'] == 'C') { |
| 503 | if (isset($scs[$uts[$j]['TsumegoStatus']['tsumego_id']])) { |
| 504 | $solvedUts2 += $scs[$uts[$j]['TsumegoStatus']['tsumego_id']]; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | Auth::getUser()['solved'] = $solvedUts2; |
| 509 | Auth::saveUser(); |
| 510 | |
| 511 | return $solvedUts2; |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * @return void |
| 516 | */ |
| 517 | protected function resetUserElos() { |
| 518 | $this->loadModel('User'); |
| 519 | |
| 520 | $u = $this->User->find('all', [ |
| 521 | 'conditions' => [ |
| 522 | 'id >=' => 15000, |
| 523 | 'id <=' => 19000, |
| 524 | ], |
| 525 | ]); |
| 526 | if (!$u) { |
| 527 | $u = []; |
| 528 | } |
| 529 | |
| 530 | $uCount = count($u); |
| 531 | for ($i = 0; $i < $uCount; $i++) { |
| 532 | $u[$i]['User']['rating'] = 900; |
| 533 | $u[$i]['User']['solved2'] = 0; |
| 534 | $this->User->save($u[$i]); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * @param int $uid User ID |
| 540 | * @param string $action Action type |
| 541 | * |
| 542 | * @return void |
| 543 | */ |
| 544 | public static function handleContribution($uid, $action) { |
| 545 | $uc = ClassRegistry::init('UserContribution')->find('first', ['conditions' => ['user_id' => $uid]]); |
| 546 | if ($uc == null) { |
| 547 | $uc = []; |
| 548 | $uc['UserContribution']['user_id'] = $uid; |
| 549 | $uc['UserContribution']['added_tag'] = 0; |
| 550 | $uc['UserContribution']['created_tag'] = 0; |
| 551 | $uc['UserContribution']['made_proposal'] = 0; |
| 552 | $uc['UserContribution']['reviewed'] = 0; |
| 553 | $uc['UserContribution']['score'] = 0; |
| 554 | ClassRegistry::init('UserContribution')->create(); |
| 555 | } |
| 556 | $uc['UserContribution'][$action] += 1; |
| 557 | $uc['UserContribution']['score'] |
| 558 | = $uc['UserContribution']['added_tag'] |
| 559 | + $uc['UserContribution']['created_tag'] * 3 |
| 560 | + $uc['UserContribution']['made_proposal'] * 5 |
| 561 | + $uc['UserContribution']['reviewed'] * 2; |
| 562 | ClassRegistry::init('UserContribution')->save($uc); |
| 563 | } |
| 564 | |
| 565 | public static function getAllTags($not) { |
| 566 | $a = []; |
| 567 | $notApproved = ClassRegistry::init('TagName')->find('all', ['conditions' => ['approved' => 0]]); |
| 568 | if (!$notApproved) { |
| 569 | $notApproved = []; |
| 570 | } |
| 571 | $notCount = count($not); |
| 572 | for ($i = 0; $i < $notCount; $i++) { |
| 573 | array_push($a, $not[$i]['Tag']['tag_name_id']); |
| 574 | } |
| 575 | $notApprovedCount = count($notApproved); |
| 576 | for ($i = 0; $i < $notApprovedCount; $i++) { |
| 577 | array_push($a, $notApproved[$i]['TagName']['id']); |
| 578 | } |
| 579 | $tn = ClassRegistry::init('TagName')->find('all', [ |
| 580 | 'conditions' => [ |
| 581 | 'NOT' => ['id' => $a], |
| 582 | ], |
| 583 | ]); |
| 584 | if (!$tn) { |
| 585 | $tn = []; |
| 586 | } |
| 587 | $sorted = []; |
| 588 | $keys = []; |
| 589 | $tnCount = count($tn); |
| 590 | for ($i = 0; $i < $tnCount; $i++) { |
| 591 | array_push($sorted, $tn[$i]['TagName']['name']); |
| 592 | $keys[$tn[$i]['TagName']['name']] = $tn[$i]; |
| 593 | } |
| 594 | sort($sorted); |
| 595 | $s2 = []; |
| 596 | $sortedCount = count($sorted); |
| 597 | for ($i = 0; $i < $sortedCount; $i++) { |
| 598 | array_push($s2, $keys[$sorted[$i]]); |
| 599 | } |
| 600 | |
| 601 | return $s2; |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * @return void |
| 606 | */ |
| 607 | protected function deleteUserBoards() { |
| 608 | $this->loadModel('UserBoard'); |
| 609 | $this->UserBoard->deleteAll(['1 = 1']); |
| 610 | } |
| 611 | |
| 612 | protected function getNewTsumego() { |
| 613 | $this->loadModel('Schedule'); |
| 614 | $date = date('Y-m-d', strtotime('today')); |
| 615 | $s = $this->Schedule->find('all', ['conditions' => ['date' => $date]]); |
| 616 | if (!$s) { |
| 617 | $s = []; |
| 618 | } |
| 619 | $id = 0; |
| 620 | $sCount = count($s); |
| 621 | for ($i = 0; $i < $sCount; $i++) { |
| 622 | $id = $this->publishSingle($s[$i]['Schedule']['tsumego_id'], $s[$i]['Schedule']['set_id'], $s[$i]['Schedule']['date']); |
| 623 | $s[$i]['Schedule']['tsumego_id'] = $id; |
| 624 | $s[$i]['Schedule']['published'] = 1; |
| 625 | $this->Schedule->save($s[$i]); |
| 626 | } |
| 627 | |
| 628 | return $id; |
| 629 | } |
| 630 | |
| 631 | protected function publishSingle($t = null, $to = null, $date = null) { |
| 632 | $this->loadModel('Tsumego'); |
| 633 | $this->loadModel('Sgf'); |
| 634 | $this->loadModel('SetConnection'); |
| 635 | $this->loadModel('PublishDate'); |
| 636 | $ts = $this->Tsumego->findById($t); |
| 637 | |
| 638 | $id = $this->Tsumego->find('first', ['limit' => 1, 'order' => 'id DESC']); |
| 639 | if (!$id) { |
| 640 | return null; |
| 641 | } |
| 642 | $id = $id['Tsumego']['id']; |
| 643 | $id += 1; |
| 644 | |
| 645 | $scT = $this->SetConnection->find('first', ['conditions' => ['tsumego_id' => $ts['Tsumego']['id']]]); |
| 646 | if ($scT != null) { |
| 647 | $scT['SetConnection']['set_id'] = $to; |
| 648 | $scT['SetConnection']['tsumego_id'] = $id; |
| 649 | $scT['SetConnection']['num'] = $ts['Tsumego']['num']; |
| 650 | $this->SetConnection->save($scT); |
| 651 | } else { |
| 652 | $scT = []; |
| 653 | $scT['SetConnection']['set_id'] = $to; |
| 654 | $scT['SetConnection']['tsumego_id'] = $id; |
| 655 | $scT['SetConnection']['num'] = $ts['Tsumego']['num']; |
| 656 | $this->SetConnection->create(); |
| 657 | $this->SetConnection->save($scT); |
| 658 | } |
| 659 | |
| 660 | $sid = $ts['Tsumego']['id']; |
| 661 | $ts['Tsumego']['id'] = $id; |
| 662 | $ts['Tsumego']['created'] = $date . ' 22:00:00'; |
| 663 | $ts['Tsumego']['solved'] = 0; |
| 664 | $ts['Tsumego']['failed'] = 0; |
| 665 | $ts['Tsumego']['userWin'] = 0; |
| 666 | $ts['Tsumego']['userLoss'] = 0; |
| 667 | $this->Tsumego->create(); |
| 668 | $this->Tsumego->save($ts); |
| 669 | $this->Tsumego->delete($sid); |
| 670 | |
| 671 | $sgfs = $this->Sgf->find('all', ['conditions' => ['tsumego_id' => $t]]); |
| 672 | if (!$sgfs) { |
| 673 | $sgfs = []; |
| 674 | } |
| 675 | $sgfsCount = count($sgfs); |
| 676 | for ($i = 0; $i < $sgfsCount; $i++) { |
| 677 | $sgfs[$i]['Sgf']['tsumego_id'] = $id; |
| 678 | $this->Sgf->save($sgfs[$i]); |
| 679 | } |
| 680 | $x = []; |
| 681 | $x['PublishDate']['date'] = $date . ' 22:00:00'; |
| 682 | $x['PublishDate']['tsumego_id'] = $id; |
| 683 | $this->PublishDate->create(); |
| 684 | $this->PublishDate->save($x); |
| 685 | |
| 686 | return $id; |
| 687 | } |
| 688 | |
| 689 | protected function getTsumegoOfTheDay() { |
| 690 | $this->loadModel('TsumegoAttempt'); |
| 691 | $this->loadModel('TsumegoRatingAttempt'); |
| 692 | $this->loadModel('Schedule'); |
| 693 | $this->loadModel('Tsumego'); |
| 694 | $this->loadModel('SetConnection'); |
| 695 | |
| 696 | $ut = $this->TsumegoRatingAttempt->find('all', ['limit' => 10000, 'order' => 'created DESC', 'conditions' => ['status' => 'S']]); |
| 697 | if (!$ut) { |
| 698 | $ut = []; |
| 699 | } |
| 700 | $out = $this->TsumegoAttempt->find('all', ['limit' => 30000, 'order' => 'updated DESC', 'conditions' => ['gain >=' => 40]]); |
| 701 | if (!$out) { |
| 702 | $out = []; |
| 703 | } |
| 704 | |
| 705 | $date = date('Y-m-d', strtotime('yesterday')); |
| 706 | $s = $this->Schedule->find('all', ['conditions' => ['date' => $date]]); |
| 707 | if (!$s) { |
| 708 | $s = []; |
| 709 | } |
| 710 | $ids = []; |
| 711 | $utCount = count($ut); |
| 712 | for ($i = 0; $i < $utCount; $i++) { |
| 713 | $date2 = new DateTime($ut[$i]['TsumegoRatingAttempt']['created']); |
| 714 | $date2 = $date2->format('Y-m-d'); |
| 715 | if ($date === $date2) { |
| 716 | array_push($ids, $ut[$i]['TsumegoRatingAttempt']['tsumego_id']); |
| 717 | } |
| 718 | } |
| 719 | $ids = array_count_values($ids); |
| 720 | $highest = 0; |
| 721 | $best = []; |
| 722 | foreach ($ids as $key => $value) { |
| 723 | if ($value > $highest) { |
| 724 | $highest = $value; |
| 725 | } |
| 726 | } |
| 727 | foreach ($ids as $key => $value) { |
| 728 | if ($value == $highest) { |
| 729 | $x = []; |
| 730 | $x[$key] = $value; |
| 731 | array_push($best, $x); |
| 732 | } |
| 733 | } |
| 734 | $ids2 = []; |
| 735 | $out2 = []; |
| 736 | $outCount = count($out); |
| 737 | for ($i = 0; $i < $outCount; $i++) { |
| 738 | $date2 = new DateTime($out[$i]['TsumegoAttempt']['updated']); |
| 739 | $date2 = $date2->format('Y-m-d'); |
| 740 | if ($date === $date2) { |
| 741 | array_push($ids2, $out[$i]['TsumegoAttempt']['tsumego_id']); |
| 742 | array_push($out2, $out[$i]); |
| 743 | } |
| 744 | } |
| 745 | $ids2 = array_count_values($ids2); |
| 746 | $highest = 0; |
| 747 | $best2 = []; |
| 748 | foreach ($ids2 as $key => $value) { |
| 749 | if ($value > $highest) { |
| 750 | $highest = $value; |
| 751 | } |
| 752 | } |
| 753 | $done = false; |
| 754 | $found = 0; |
| 755 | $decrement = 0; |
| 756 | $best3 = []; |
| 757 | $findNum = 20; |
| 758 | while (!$done) { |
| 759 | foreach ($ids2 as $key => $value) { |
| 760 | if ($value == $highest - $decrement) { |
| 761 | array_push($best2, $key); |
| 762 | array_push($best3, $value); |
| 763 | $found++; |
| 764 | } |
| 765 | } |
| 766 | $decrement++; |
| 767 | if ($found < $findNum) { |
| 768 | $done = false; |
| 769 | } else { |
| 770 | $done = true; |
| 771 | } |
| 772 | } |
| 773 | $newBest = []; |
| 774 | for ($j = 0; $j < $findNum; $j++) { |
| 775 | $newBest[$j] = []; |
| 776 | } |
| 777 | $out2Count = count($out2); |
| 778 | for ($i = 0; $i < $out2Count; $i++) { |
| 779 | for ($j = 0; $j < $findNum; $j++) { |
| 780 | if ($out2[$i]['TsumegoAttempt']['tsumego_id'] == $best2[$j]) { |
| 781 | $x = []; |
| 782 | $x['tid'] = $out2[$i]['TsumegoAttempt']['tsumego_id']; |
| 783 | $tx = $this->Tsumego->findById($x['tid']); |
| 784 | $scT = $this->SetConnection->find('first', ['conditions' => ['tsumego_id' => $tx['Tsumego']['id']]]); |
| 785 | $tx['Tsumego']['set_id'] = $scT['SetConnection']['set_id']; |
| 786 | $x['sid'] = $tx['Tsumego']['set_id']; |
| 787 | $x['status'] = $out2[$i]['TsumegoAttempt']['solved']; |
| 788 | $x['seconds'] = $out2[$i]['TsumegoAttempt']['seconds']; |
| 789 | |
| 790 | $newBest[$j][] = $x; |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | $newBestCount = count($newBest); |
| 795 | for ($i = 0; $i < $newBestCount; $i++) { |
| 796 | $sum = 0; |
| 797 | $newBestICount = count($newBest[$i]); |
| 798 | for ($j = 0; $j < $newBestICount; $j++) { |
| 799 | if ($newBest[$i][$j]['seconds'] != null) { |
| 800 | if ($newBest[$i][$j]['seconds'] > 300) { |
| 801 | $newBest[$i][$j]['seconds'] = 300; |
| 802 | } |
| 803 | $sum += $newBest[$i][$j]['seconds']; |
| 804 | } |
| 805 | } |
| 806 | $sum = $sum * count($newBest[$i]); |
| 807 | $newBest[$i]['sum'] = $sum; |
| 808 | } |
| 809 | $highest = 0; |
| 810 | $hid = 0; |
| 811 | $newBestCount = count($newBest); |
| 812 | for ($i = 0; $i < $newBestCount; $i++) { |
| 813 | if ($newBest[$i]['sum'] > $highest && $newBest[$i][0]['sid'] != 104 && $newBest[$i][0]['sid'] != 105 && $newBest[$i][0]['sid'] != 117) { |
| 814 | $yesterday = false; |
| 815 | $sCount = count($s); |
| 816 | for ($j = 0; $j < $sCount; $j++) { |
| 817 | if ($newBest[$i][0]['tid'] == $s[$j]['Schedule']['tsumego_id']) { |
| 818 | $yesterday = true; |
| 819 | } |
| 820 | } |
| 821 | if (!$yesterday) { |
| 822 | $highest = $newBest[$i]['sum']; |
| 823 | $hid = $i; |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | return $newBest[$hid][0]['tid']; |
| 829 | } |
| 830 | |
| 831 | protected function ratingMatch($elo) { |
| 832 | if ($elo >= 3000) { |
| 833 | $td = 10;//10d |
| 834 | } elseif ($elo >= 2900) { |
| 835 | $td = 10;//9d |
| 836 | } elseif ($elo >= 2800) { |
| 837 | $td = 10;//8d |
| 838 | } elseif ($elo >= 2700) { |
| 839 | $td = 10;//7d x2700 |
| 840 | } elseif ($elo >= 2600) { |
| 841 | $td = 9;//6d x2600 |
| 842 | } elseif ($elo >= 2500) { |
| 843 | $td = 8;//5d x2500 |
| 844 | } elseif ($elo >= 2400) { |
| 845 | $td = 7;//4d |
| 846 | } elseif ($elo >= 2300) { |
| 847 | $td = 7;//3d x2350 |
| 848 | } elseif ($elo >= 2200) { |
| 849 | $td = 6;//2d |
| 850 | } elseif ($elo >= 2100) { |
| 851 | $td = 6;//1d x2150 |
| 852 | } elseif ($elo >= 2000) { |
| 853 | $td = 5;//1k |
| 854 | } elseif ($elo >= 1900) { |
| 855 | $td = 5;//2k x1950 |
| 856 | } elseif ($elo >= 1800) { |
| 857 | $td = 4;//3k |
| 858 | } elseif ($elo >= 1700) { |
| 859 | $td = 4;//4k x1750 |
| 860 | } elseif ($elo >= 1600) { |
| 861 | $td = 3;//5k |
| 862 | } elseif ($elo >= 1500) { |
| 863 | $td = 3;//6k x1500 |
| 864 | } elseif ($elo >= 1400) { |
| 865 | $td = 3;//7k |
| 866 | } elseif ($elo >= 1300) { |
| 867 | $td = 2;//8k |
| 868 | } elseif ($elo >= 1200) { |
| 869 | $td = 2;//9k x1200 |
| 870 | } elseif ($elo >= 1100) { |
| 871 | $td = 2;//10k |
| 872 | } elseif ($elo >= 1000) { |
| 873 | $td = 1;//11k |
| 874 | } elseif ($elo >= 900) { |
| 875 | $td = 1;//12k x900 |
| 876 | } elseif ($elo >= 800) { |
| 877 | $td = 1;//13k |
| 878 | } elseif ($elo >= 700) { |
| 879 | $td = 1;//14k |
| 880 | } elseif ($elo >= 600) { |
| 881 | $td = 1;//15k |
| 882 | } elseif ($elo >= 500) { |
| 883 | $td = 1;//16k |
| 884 | } elseif ($elo >= 400) { |
| 885 | $td = 1;//17k |
| 886 | } elseif ($elo >= 300) { |
| 887 | $td = 1;//18k |
| 888 | } elseif ($elo >= 200) { |
| 889 | $td = 1;//19k |
| 890 | } elseif ($elo >= 100) { |
| 891 | $td = 1;//20k |
| 892 | } else { |
| 893 | $td = 1; |
| 894 | } |
| 895 | |
| 896 | return $td; |
| 897 | } |
| 898 | |
| 899 | protected function rating2($d) { |
| 900 | if ($d == 10) { |
| 901 | $elo = 2700; |
| 902 | } elseif ($d == 9) { |
| 903 | $elo = 2600; |
| 904 | } elseif ($d == 8) { |
| 905 | $elo = 2500; |
| 906 | } elseif ($d == 7) { |
| 907 | $elo = 2350; |
| 908 | } elseif ($d == 6) { |
| 909 | $elo = 2150; |
| 910 | } elseif ($d == 5) { |
| 911 | $elo = 1950; |
| 912 | } elseif ($d == 4) { |
| 913 | $elo = 1750; |
| 914 | } elseif ($d == 3) { |
| 915 | $elo = 1500; |
| 916 | } elseif ($d == 2) { |
| 917 | $elo = 1200; |
| 918 | } elseif ($d == 1) { |
| 919 | $elo = 900; |
| 920 | } else { |
| 921 | $elo = 1500; |
| 922 | } |
| 923 | |
| 924 | return $elo; |
| 925 | } |
| 926 | |
| 927 | public static function encrypt($str = null) { |
| 928 | $secret_key = 'my_simple_secret_keyx'; |
| 929 | $secret_iv = 'my_simple_secret_ivx'; |
| 930 | $encrypt_method = 'AES-256-CBC'; |
| 931 | $key = hash('sha256', $secret_key); |
| 932 | $iv = substr(hash('sha256', $secret_iv), 0, 16); |
| 933 | |
| 934 | return base64_encode(openssl_encrypt($str, $encrypt_method, $key, 0, $iv)); |
| 935 | } |
| 936 | |
| 937 | public static function decrypt($str = null) { |
| 938 | $string = $str; |
| 939 | $secret_key = 'my_simple_secret_keyx'; |
| 940 | $secret_iv = 'my_simple_secret_ivx'; |
| 941 | $encrypt_method = 'AES-256-CBC'; |
| 942 | $key = hash('sha256', $secret_key); |
| 943 | $iv = substr(hash('sha256', $secret_iv), 0, 16); |
| 944 | |
| 945 | return openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); |
| 946 | } |
| 947 | |
| 948 | protected function checkPictureLarge($u) { |
| 949 | if (substr($u['User']['name'], 0, 3) == 'g__' && $u['User']['external_id'] != null) { |
| 950 | return '<img class="google-profile-image-large" src="/img/google/' . $u['User']['picture'] . '">' . substr($u['User']['name'], 3); |
| 951 | } |
| 952 | |
| 953 | return $u['User']['name']; |
| 954 | } |
| 955 | public static function checkPicture($user) { |
| 956 | if (substr($user['name'], 0, 3) == 'g__' && $user['external_id'] != null) { |
| 957 | return '<img class="google-profile-image" src="/img/google/' . $user['picture'] . '">' . substr($user['name'], 3); |
| 958 | } |
| 959 | |
| 960 | return $user['name']; |
| 961 | } |
| 962 | |
| 963 | public static function getTsumegoRankx($t) { |
| 964 | if ($t <= 0) { |
| 965 | return '15k'; |
| 966 | } |
| 967 | if ($t > 0 && $t <= 22) { |
| 968 | $tRank = '5d'; |
| 969 | } elseif ($t <= 26.5) { |
| 970 | $tRank = '4d'; |
| 971 | } elseif ($t <= 30) { |
| 972 | $tRank = '3d'; |
| 973 | } elseif ($t <= 34) { |
| 974 | $tRank = '2d'; |
| 975 | } elseif ($t <= 38) { |
| 976 | $tRank = '1d'; |
| 977 | } elseif ($t <= 42) { |
| 978 | $tRank = '1k'; |
| 979 | } elseif ($t <= 46) { |
| 980 | $tRank = '2k'; |
| 981 | } elseif ($t <= 50) { |
| 982 | $tRank = '3k'; |
| 983 | } elseif ($t <= 54.5) { |
| 984 | $tRank = '4k'; |
| 985 | } elseif ($t <= 58.5) { |
| 986 | $tRank = '5k'; |
| 987 | } elseif ($t <= 63) { |
| 988 | $tRank = '6k'; |
| 989 | } elseif ($t <= 67) { |
| 990 | $tRank = '7k'; |
| 991 | } elseif ($t <= 70.8) { |
| 992 | $tRank = '8k'; |
| 993 | } elseif ($t <= 74.8) { |
| 994 | $tRank = '9k'; |
| 995 | } elseif ($t <= 79) { |
| 996 | $tRank = '10k'; |
| 997 | } elseif ($t <= 83.5) { |
| 998 | $tRank = '11k'; |
| 999 | } elseif ($t <= 88) { |
| 1000 | $tRank = '12k'; |
| 1001 | } elseif ($t <= 92) { |
| 1002 | $tRank = '13k'; |
| 1003 | } elseif ($t <= 96) { |
| 1004 | $tRank = '14k'; |
| 1005 | } else { |
| 1006 | $tRank = '15k'; |
| 1007 | } |
| 1008 | |
| 1009 | return $tRank; |
| 1010 | } |
| 1011 | protected function adjustElo($v) { |
| 1012 | $add = 0; |
| 1013 | if ($v >= 1700) { |
| 1014 | $add = 110; |
| 1015 | } elseif ($v >= 1600) { |
| 1016 | $add = 110; |
| 1017 | } elseif ($v >= 1700) { |
| 1018 | $add = 100; |
| 1019 | } elseif ($v >= 1600) { |
| 1020 | $add = 90; |
| 1021 | } elseif ($v >= 1500) { |
| 1022 | $add = 80; |
| 1023 | } elseif ($v >= 1400) { |
| 1024 | $add = 70; |
| 1025 | } elseif ($v >= 1300) { |
| 1026 | $add = 60; |
| 1027 | } elseif ($v >= 1200) { |
| 1028 | $add = 60; |
| 1029 | } elseif ($v >= 1100) { |
| 1030 | $add = 50; |
| 1031 | } elseif ($v >= 1000) { |
| 1032 | $add = 50; |
| 1033 | } else { |
| 1034 | $add = 0; |
| 1035 | } |
| 1036 | |
| 1037 | return $v + $add; |
| 1038 | } |
| 1039 | |
| 1040 | public static function getTsumegoElo($rank, $p = null) { |
| 1041 | if ($p != null) { |
| 1042 | $p *= 100; |
| 1043 | } else { |
| 1044 | $p = 0; |
| 1045 | } |
| 1046 | $elo = 600; |
| 1047 | if ($rank == '9d') { |
| 1048 | $elo = round(2900 + $p); |
| 1049 | } elseif ($rank == '8d') { |
| 1050 | $elo = round(2800 + $p); |
| 1051 | } elseif ($rank == '7d') { |
| 1052 | $elo = round(2700 + $p); |
| 1053 | } elseif ($rank == '6d') { |
| 1054 | $elo = round(2600 + $p); |
| 1055 | } elseif ($rank == '5d') { |
| 1056 | $elo = round(2500 + $p); |
| 1057 | } elseif ($rank == '4d') { |
| 1058 | $elo = round(2400 + $p); |
| 1059 | } elseif ($rank == '3d') { |
| 1060 | $elo = round(2300 + $p); |
| 1061 | } elseif ($rank == '2d') { |
| 1062 | $elo = round(2200 + $p); |
| 1063 | } elseif ($rank == '1d') { |
| 1064 | $elo = round(2100 + $p); |
| 1065 | } elseif ($rank == '1k') { |
| 1066 | $elo = round(2000 + $p); |
| 1067 | } elseif ($rank == '2k') { |
| 1068 | $elo = round(1900 + $p); |
| 1069 | } elseif ($rank == '3k') { |
| 1070 | $elo = round(1800 + $p); |
| 1071 | } elseif ($rank == '4k') { |
| 1072 | $elo = round(1700 + $p); |
| 1073 | } elseif ($rank == '5k') { |
| 1074 | $elo = round(1600 + $p); |
| 1075 | } elseif ($rank == '6k') { |
| 1076 | $elo = round(1500 + $p); |
| 1077 | } elseif ($rank == '7k') { |
| 1078 | $elo = round(1400 + $p); |
| 1079 | } elseif ($rank == '8k') { |
| 1080 | $elo = round(1300 + $p); |
| 1081 | } elseif ($rank == '9k') { |
| 1082 | $elo = round(1200 + $p); |
| 1083 | } elseif ($rank == '10k') { |
| 1084 | $elo = round(1100 + $p); |
| 1085 | } elseif ($rank == '11k') { |
| 1086 | $elo = round(1000 + $p); |
| 1087 | } elseif ($rank == '12k') { |
| 1088 | $elo = round(900 + $p); |
| 1089 | } elseif ($rank == '13k') { |
| 1090 | $elo = round(800 + $p); |
| 1091 | } elseif ($rank == '14k') { |
| 1092 | $elo = round(700 + $p); |
| 1093 | } elseif ($rank == '15k' || $rank == '16k' || $rank == '17k' || $rank == '18k' || $rank == '19k' || $rank == '20k' || $rank == '21k') { |
| 1094 | $elo = round(600 + $p); |
| 1095 | } |
| 1096 | |
| 1097 | return $elo; |
| 1098 | } |
| 1099 | protected function getTsumegoRankVal($t) { |
| 1100 | if ($t <= 0) { |
| 1101 | return 0; |
| 1102 | } |
| 1103 | if ($t > 0 && $t <= 22) { |
| 1104 | return 22 - $t; |
| 1105 | } |
| 1106 | if ($t <= 26.5) { |
| 1107 | return 26.5 - $t; |
| 1108 | } |
| 1109 | if ($t <= 30) { |
| 1110 | return 30 - $t; |
| 1111 | } |
| 1112 | if ($t <= 34) { |
| 1113 | return 34 - $t; |
| 1114 | } |
| 1115 | if ($t <= 38) { |
| 1116 | return 38 - $t; |
| 1117 | } |
| 1118 | if ($t <= 42) { |
| 1119 | return 42 - $t; |
| 1120 | } |
| 1121 | if ($t <= 46) { |
| 1122 | return 46 - $t; |
| 1123 | } |
| 1124 | if ($t <= 50) { |
| 1125 | return 50 - $t; |
| 1126 | } |
| 1127 | if ($t <= 54.5) { |
| 1128 | return 54.5 - $t; |
| 1129 | } |
| 1130 | if ($t <= 58.5) { |
| 1131 | return 58.5 - $t; |
| 1132 | } |
| 1133 | if ($t <= 63) { |
| 1134 | return 63 - $t; |
| 1135 | } |
| 1136 | if ($t <= 67) { |
| 1137 | return 67 - $t; |
| 1138 | } |
| 1139 | if ($t <= 70.8) { |
| 1140 | return 70.8 - $t; |
| 1141 | } |
| 1142 | if ($t <= 74.8) { |
| 1143 | return 74.8 - $t; |
| 1144 | } |
| 1145 | if ($t <= 79) { |
| 1146 | return 79 - $t; |
| 1147 | } |
| 1148 | if ($t <= 83.5) { |
| 1149 | return 83.5 - $t; |
| 1150 | } |
| 1151 | if ($t <= 88) { |
| 1152 | return 88 - $t; |
| 1153 | } |
| 1154 | if ($t <= 92) { |
| 1155 | return 92 - $t; |
| 1156 | } |
| 1157 | if ($t <= 96) { |
| 1158 | return 96 - $t; |
| 1159 | } |
| 1160 | |
| 1161 | return 100 - $t; |
| 1162 | } |
| 1163 | protected function getTsumegoRankMax($t) { |
| 1164 | if ($t <= 0) { |
| 1165 | return 100 - 96; |
| 1166 | } |
| 1167 | if ($t > 0 && $t <= 22) { |
| 1168 | return 22; |
| 1169 | } |
| 1170 | if ($t <= 26.5) { |
| 1171 | return 26.5 - 22; |
| 1172 | } |
| 1173 | if ($t <= 30) { |
| 1174 | return 30 - 26.5; |
| 1175 | } |
| 1176 | if ($t <= 34) { |
| 1177 | return 34 - 30; |
| 1178 | } |
| 1179 | if ($t <= 38) { |
| 1180 | return 38 - 34; |
| 1181 | } |
| 1182 | if ($t <= 42) { |
| 1183 | return 42 - 38; |
| 1184 | } |
| 1185 | if ($t <= 46) { |
| 1186 | return 46 - 42; |
| 1187 | } |
| 1188 | if ($t <= 50) { |
| 1189 | return 50 - 46; |
| 1190 | } |
| 1191 | if ($t <= 54.5) { |
| 1192 | return 54.5 - 50; |
| 1193 | } |
| 1194 | if ($t <= 58.5) { |
| 1195 | return 58.5 - 54.5; |
| 1196 | } |
| 1197 | if ($t <= 63) { |
| 1198 | return 63 - 58.5; |
| 1199 | } |
| 1200 | if ($t <= 67) { |
| 1201 | return 67 - 63; |
| 1202 | } |
| 1203 | if ($t <= 70.8) { |
| 1204 | return 70.8 - 67; |
| 1205 | } |
| 1206 | if ($t <= 74.8) { |
| 1207 | return 74.8 - 70.8; |
| 1208 | } |
| 1209 | if ($t <= 79) { |
| 1210 | return 79 - 74.8; |
| 1211 | } |
| 1212 | if ($t <= 83.5) { |
| 1213 | return 83.5 - 79; |
| 1214 | } |
| 1215 | if ($t <= 88) { |
| 1216 | return 88 - 83.5; |
| 1217 | } |
| 1218 | if ($t <= 92) { |
| 1219 | return 92 - 88; |
| 1220 | } |
| 1221 | if ($t <= 96) { |
| 1222 | return 96 - 92; |
| 1223 | } |
| 1224 | |
| 1225 | return 100 - 96; |
| 1226 | } |
| 1227 | |
| 1228 | public static function saveDanSolveCondition($solvedTsumegoRank, $tId): void { |
| 1229 | if ($solvedTsumegoRank == '1d' || $solvedTsumegoRank == '2d' || $solvedTsumegoRank == '3d' || $solvedTsumegoRank == '4d' || $solvedTsumegoRank == '5d') { |
| 1230 | $danSolveCategory = 'danSolve' . $solvedTsumegoRank; |
| 1231 | $danSolveCondition = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 1232 | 'order' => 'value DESC', |
| 1233 | 'conditions' => [ |
| 1234 | 'user_id' => Auth::getUserID(), |
| 1235 | 'category' => $danSolveCategory, |
| 1236 | ], |
| 1237 | ]); |
| 1238 | if (!$danSolveCondition) { |
| 1239 | $danSolveCondition = []; |
| 1240 | $danSolveCondition['AchievementCondition']['value'] = 0; |
| 1241 | ClassRegistry::init('AchievementCondition')->create(); |
| 1242 | } |
| 1243 | $danSolveCondition['AchievementCondition']['category'] = $danSolveCategory; |
| 1244 | $danSolveCondition['AchievementCondition']['user_id'] = Auth::getUserID(); |
| 1245 | $danSolveCondition['AchievementCondition']['set_id'] = $tId; |
| 1246 | $danSolveCondition['AchievementCondition']['value']++; |
| 1247 | |
| 1248 | ClassRegistry::init('AchievementCondition')->save($danSolveCondition); |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | public static function updateSprintCondition(bool $trigger = false): void { |
| 1253 | if (Auth::isLoggedIn()) { |
| 1254 | $sprintCondition = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 1255 | 'order' => 'value DESC', |
| 1256 | 'conditions' => [ |
| 1257 | 'user_id' => Auth::getUserID(), |
| 1258 | 'category' => 'sprint', |
| 1259 | ], |
| 1260 | ]); |
| 1261 | if (!$sprintCondition) { |
| 1262 | $sprintCondition = []; |
| 1263 | $sprintCondition['AchievementCondition']['value'] = 0; |
| 1264 | ClassRegistry::init('AchievementCondition')->create(); |
| 1265 | } |
| 1266 | $sprintCondition['AchievementCondition']['category'] = 'sprint'; |
| 1267 | $sprintCondition['AchievementCondition']['user_id'] = Auth::getUserID(); |
| 1268 | if ($trigger) { |
| 1269 | $sprintCondition['AchievementCondition']['value']++; |
| 1270 | } else { |
| 1271 | $sprintCondition['AchievementCondition']['value'] = 0; |
| 1272 | } |
| 1273 | ClassRegistry::init('AchievementCondition')->save($sprintCondition); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | public static function updateGoldenCondition(bool $trigger = false): void { |
| 1278 | $goldenCondition = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 1279 | 'order' => 'value DESC', |
| 1280 | 'conditions' => [ |
| 1281 | 'user_id' => Auth::getUserID(), |
| 1282 | 'category' => 'golden', |
| 1283 | ], |
| 1284 | ]); |
| 1285 | if (!$goldenCondition) { |
| 1286 | $goldenCondition = []; |
| 1287 | $goldenCondition['AchievementCondition']['value'] = 0; |
| 1288 | ClassRegistry::init('AchievementCondition')->create(); |
| 1289 | } |
| 1290 | $goldenCondition['AchievementCondition']['category'] = 'golden'; |
| 1291 | $goldenCondition['AchievementCondition']['user_id'] = Auth::getUserID(); |
| 1292 | if ($trigger) { |
| 1293 | $goldenCondition['AchievementCondition']['value']++; |
| 1294 | } else { |
| 1295 | $goldenCondition['AchievementCondition']['value'] = 0; |
| 1296 | } |
| 1297 | ClassRegistry::init('AchievementCondition')->save($goldenCondition); |
| 1298 | } |
| 1299 | |
| 1300 | public static function setPotionCondition(): void { |
| 1301 | $potionCondition = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 1302 | 'order' => 'value DESC', |
| 1303 | 'conditions' => [ |
| 1304 | 'user_id' => Auth::getUserID(), |
| 1305 | 'category' => 'potion', |
| 1306 | ], |
| 1307 | ]); |
| 1308 | if (!$potionCondition) { |
| 1309 | $potionCondition = []; |
| 1310 | ClassRegistry::init('AchievementCondition')->create(); |
| 1311 | } |
| 1312 | $potionCondition['AchievementCondition']['category'] = 'potion'; |
| 1313 | $potionCondition['AchievementCondition']['user_id'] = Auth::getUserID(); |
| 1314 | $potionCondition['AchievementCondition']['value'] = 1; |
| 1315 | ClassRegistry::init('AchievementCondition')->save($potionCondition); |
| 1316 | } |
| 1317 | |
| 1318 | public static function updateGems(string $rank): void { |
| 1319 | $datex = new DateTime('today'); |
| 1320 | $dateGem = ClassRegistry::init('DayRecord')->find('first', ['conditions' => ['date' => $datex->format('Y-m-d')]]); |
| 1321 | if ($dateGem != null) { |
| 1322 | $gems = explode('-', $dateGem['DayRecord']['gems']); |
| 1323 | $gemValue = ''; |
| 1324 | $gemValue2 = ''; |
| 1325 | $gemValue3 = ''; |
| 1326 | $condition1 = 500; |
| 1327 | $condition2 = 200; |
| 1328 | $condition3 = 5; |
| 1329 | $found1 = false; |
| 1330 | $found2 = false; |
| 1331 | $found3 = false; |
| 1332 | if ($rank == '15k' || $rank == '14k' || $rank == '13k' || $rank == '12k' || $rank == '11k' || $rank == '10k') { |
| 1333 | if ($gems[0] == 0) { |
| 1334 | $gemValue = '15k'; |
| 1335 | } elseif ($gems[0] == 1) { |
| 1336 | $gemValue = '12k'; |
| 1337 | } elseif ($gems[0] == 2) { |
| 1338 | $gemValue = '10k'; |
| 1339 | } |
| 1340 | if ($rank == $gemValue) { |
| 1341 | $dateGem['DayRecord']['gemCounter1']++; |
| 1342 | if ($dateGem['DayRecord']['gemCounter1'] == $condition1) { |
| 1343 | $found1 = true; |
| 1344 | } |
| 1345 | } |
| 1346 | } elseif ($rank == '9k' || $rank == '8k' || $rank == '7k' || $rank == '6k' || $rank == '5k' || $rank == '4k' || $rank == '3k' || $rank == '2k' || $rank == '1k') { |
| 1347 | if ($gems[1] == 0) { |
| 1348 | $gemValue = '9k'; |
| 1349 | $gemValue2 = 'x'; |
| 1350 | $gemValue3 = 'y'; |
| 1351 | } elseif ($gems[1] == 1) { |
| 1352 | $gemValue = '6k'; |
| 1353 | $gemValue2 = '5k'; |
| 1354 | $gemValue3 = '4k'; |
| 1355 | } elseif ($gems[1] == 2) { |
| 1356 | $gemValue = 'x'; |
| 1357 | $gemValue2 = '2k'; |
| 1358 | $gemValue3 = '1k'; |
| 1359 | } |
| 1360 | if ($rank == $gemValue || $rank == $gemValue2 || $rank == $gemValue3) { |
| 1361 | $dateGem['DayRecord']['gemCounter2']++; |
| 1362 | if ($dateGem['DayRecord']['gemCounter2'] == $condition2) { |
| 1363 | $found2 = true; |
| 1364 | } |
| 1365 | } |
| 1366 | } elseif ($rank == '1d' || $rank == '2d' || $rank == '3d' || $rank == '4d' || $rank == '5d' || $rank == '6d' || $rank == '7d') { |
| 1367 | if ($gems[2] == 0) { |
| 1368 | $gemValue = '1d'; |
| 1369 | $gemValue2 = '2d'; |
| 1370 | $gemValue3 = '3d'; |
| 1371 | } elseif ($gems[2] == 1) { |
| 1372 | $gemValue = '2d'; |
| 1373 | $gemValue2 = '3d'; |
| 1374 | $gemValue3 = '4d'; |
| 1375 | } elseif ($gems[2] == 2) { |
| 1376 | $gemValue = '5d'; |
| 1377 | $gemValue2 = '6d'; |
| 1378 | $gemValue3 = '7d'; |
| 1379 | } |
| 1380 | if ($rank == $gemValue || $rank == $gemValue2 || $rank == $gemValue3) { |
| 1381 | $dateGem['DayRecord']['gemCounter3']++; |
| 1382 | if ($dateGem['DayRecord']['gemCounter3'] == $condition3) { |
| 1383 | $found3 = true; |
| 1384 | } |
| 1385 | } |
| 1386 | } |
| 1387 | if ($found1) { |
| 1388 | $aCondition = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 1389 | 'order' => 'value DESC', |
| 1390 | 'conditions' => [ |
| 1391 | 'user_id' => Auth::getUserID(), |
| 1392 | 'category' => 'emerald', |
| 1393 | ], |
| 1394 | ]); |
| 1395 | if ($aCondition == null) { |
| 1396 | $aCondition = []; |
| 1397 | $aCondition['AchievementCondition']['category'] = 'emerald'; |
| 1398 | $aCondition['AchievementCondition']['user_id'] = Auth::getUserID(); |
| 1399 | $aCondition['AchievementCondition']['value'] = 1; |
| 1400 | ClassRegistry::init('AchievementCondition')->save($aCondition); |
| 1401 | } else { |
| 1402 | $dateGem['DayRecord']['gemCounter1']--; |
| 1403 | } |
| 1404 | } elseif ($found2) { |
| 1405 | $aCondition = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 1406 | 'order' => 'value DESC', |
| 1407 | 'conditions' => [ |
| 1408 | 'user_id' => Auth::getUserID(), |
| 1409 | 'category' => 'sapphire', |
| 1410 | ], |
| 1411 | ]); |
| 1412 | if ($aCondition == null) { |
| 1413 | $aCondition = []; |
| 1414 | $aCondition['AchievementCondition']['category'] = 'sapphire'; |
| 1415 | $aCondition['AchievementCondition']['user_id'] = Auth::getUserID(); |
| 1416 | $aCondition['AchievementCondition']['value'] = 1; |
| 1417 | ClassRegistry::init('AchievementCondition')->save($aCondition); |
| 1418 | } else { |
| 1419 | $dateGem['DayRecord']['gemCounter2']--; |
| 1420 | } |
| 1421 | } elseif ($found3) { |
| 1422 | $aCondition = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 1423 | 'order' => 'value DESC', |
| 1424 | 'conditions' => [ |
| 1425 | 'user_id' => Auth::getUserID(), |
| 1426 | 'category' => 'ruby', |
| 1427 | ], |
| 1428 | ]); |
| 1429 | if ($aCondition == null) { |
| 1430 | $aCondition = []; |
| 1431 | $aCondition['AchievementCondition']['category'] = 'ruby'; |
| 1432 | $aCondition['AchievementCondition']['user_id'] = Auth::getUserID(); |
| 1433 | $aCondition['AchievementCondition']['value'] = 1; |
| 1434 | ClassRegistry::init('AchievementCondition')->save($aCondition); |
| 1435 | } else { |
| 1436 | $dateGem['DayRecord']['gemCounter3']--; |
| 1437 | } |
| 1438 | } |
| 1439 | } |
| 1440 | ClassRegistry::init('DayRecord')->save($dateGem); |
| 1441 | } |
| 1442 | |
| 1443 | public static function checkProblemNumberAchievements() { |
| 1444 | if (!Auth::isLoggedIn()) { |
| 1445 | return; |
| 1446 | } |
| 1447 | |
| 1448 | $buffer = ClassRegistry::init('AchievementStatus')->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 1449 | if (!$buffer) { |
| 1450 | $buffer = []; |
| 1451 | } |
| 1452 | $existingAs = []; |
| 1453 | $bufferCount = count($buffer); |
| 1454 | for ($i = 0; $i < $bufferCount; $i++) { |
| 1455 | $existingAs[$buffer[$i]['AchievementStatus']['achievement_id']] = $buffer[$i]; |
| 1456 | } |
| 1457 | $as = []; |
| 1458 | $as['AchievementStatus']['user_id'] = Auth::getUserID(); |
| 1459 | $updated = []; |
| 1460 | |
| 1461 | $achievementId = 1; |
| 1462 | $solvedCount = Auth::getUser()['solved']; |
| 1463 | if ($solvedCount >= 1000 && !isset($existingAs[$achievementId])) { |
| 1464 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1465 | ClassRegistry::init('AchievementStatus')->create(); |
| 1466 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1467 | array_push($updated, $achievementId); |
| 1468 | } |
| 1469 | $achievementId = 2; |
| 1470 | if ($solvedCount >= 2000 && !isset($existingAs[$achievementId])) { |
| 1471 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1472 | ClassRegistry::init('AchievementStatus')->create(); |
| 1473 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1474 | array_push($updated, $achievementId); |
| 1475 | } |
| 1476 | $achievementId = 3; |
| 1477 | if ($solvedCount >= 3000 && !isset($existingAs[$achievementId])) { |
| 1478 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1479 | ClassRegistry::init('AchievementStatus')->create(); |
| 1480 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1481 | array_push($updated, $achievementId); |
| 1482 | } |
| 1483 | $achievementId = 4; |
| 1484 | if ($solvedCount >= 4000 && !isset($existingAs[$achievementId])) { |
| 1485 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1486 | ClassRegistry::init('AchievementStatus')->create(); |
| 1487 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1488 | array_push($updated, $achievementId); |
| 1489 | } |
| 1490 | $achievementId = 5; |
| 1491 | if ($solvedCount >= 5000 && !isset($existingAs[$achievementId])) { |
| 1492 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1493 | ClassRegistry::init('AchievementStatus')->create(); |
| 1494 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1495 | array_push($updated, $achievementId); |
| 1496 | } |
| 1497 | $achievementId = 6; |
| 1498 | if ($solvedCount >= 6000 && !isset($existingAs[$achievementId])) { |
| 1499 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1500 | ClassRegistry::init('AchievementStatus')->create(); |
| 1501 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1502 | array_push($updated, $achievementId); |
| 1503 | } |
| 1504 | $achievementId = 7; |
| 1505 | if ($solvedCount >= 7000 && !isset($existingAs[$achievementId])) { |
| 1506 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1507 | ClassRegistry::init('AchievementStatus')->create(); |
| 1508 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1509 | array_push($updated, $achievementId); |
| 1510 | } |
| 1511 | $achievementId = 8; |
| 1512 | if ($solvedCount >= 8000 && !isset($existingAs[$achievementId])) { |
| 1513 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1514 | ClassRegistry::init('AchievementStatus')->create(); |
| 1515 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1516 | array_push($updated, $achievementId); |
| 1517 | } |
| 1518 | $achievementId = 9; |
| 1519 | if ($solvedCount >= 9000 && !isset($existingAs[$achievementId])) { |
| 1520 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1521 | ClassRegistry::init('AchievementStatus')->create(); |
| 1522 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1523 | array_push($updated, $achievementId); |
| 1524 | } |
| 1525 | $achievementId = 10; |
| 1526 | if ($solvedCount >= 10000 && !isset($existingAs[$achievementId])) { |
| 1527 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1528 | ClassRegistry::init('AchievementStatus')->create(); |
| 1529 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1530 | array_push($updated, $achievementId); |
| 1531 | } |
| 1532 | //uotd achievement |
| 1533 | $achievementId = 11; |
| 1534 | if (!isset($existingAs[$achievementId])) { |
| 1535 | $condition = ClassRegistry::init('AchievementCondition')->find('first', ['conditions' => ['user_id' => Auth::getUserID(), 'category' => 'uotd']]); |
| 1536 | if ($condition != null) { |
| 1537 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1538 | ClassRegistry::init('AchievementStatus')->create(); |
| 1539 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1540 | array_push($updated, $achievementId); |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | $updatedCount = count($updated); |
| 1545 | for ($i = 0; $i < $updatedCount; $i++) { |
| 1546 | $a = ClassRegistry::init('Achievement')->findById($updated[$i]); |
| 1547 | $updated[$i] = []; |
| 1548 | $updated[$i][0] = $a['Achievement']['name']; |
| 1549 | $updated[$i][1] = $a['Achievement']['description']; |
| 1550 | $updated[$i][2] = $a['Achievement']['image']; |
| 1551 | $updated[$i][3] = $a['Achievement']['color']; |
| 1552 | $updated[$i][4] = $a['Achievement']['xp']; |
| 1553 | $updated[$i][5] = $a['Achievement']['id']; |
| 1554 | } |
| 1555 | |
| 1556 | return $updated; |
| 1557 | } |
| 1558 | |
| 1559 | public static function checkDanSolveAchievements() { |
| 1560 | if (Auth::isLoggedIn()) { |
| 1561 | $buffer = ClassRegistry::init('AchievementStatus')->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 1562 | if (!$buffer) { |
| 1563 | $buffer = []; |
| 1564 | } |
| 1565 | $ac = ClassRegistry::init('AchievementCondition')->find('all', [ |
| 1566 | 'order' => 'category ASC', |
| 1567 | 'conditions' => [ |
| 1568 | 'user_id' => Auth::getUserID(), |
| 1569 | 'OR' => [ |
| 1570 | ['category' => 'danSolve1d'], |
| 1571 | ['category' => 'danSolve2d'], |
| 1572 | ['category' => 'danSolve3d'], |
| 1573 | ['category' => 'danSolve4d'], |
| 1574 | ['category' => 'danSolve5d'], |
| 1575 | ['category' => 'emerald'], |
| 1576 | ['category' => 'sapphire'], |
| 1577 | ['category' => 'ruby'], |
| 1578 | ['category' => 'sprint'], |
| 1579 | ['category' => 'golden'], |
| 1580 | ['category' => 'potion'], |
| 1581 | ], |
| 1582 | ], |
| 1583 | ]); |
| 1584 | if (!$ac) { |
| 1585 | $ac = []; |
| 1586 | } |
| 1587 | $ac1 = []; |
| 1588 | $acCount = count($ac); |
| 1589 | for ($i = 0; $i < $acCount; $i++) { |
| 1590 | if ($ac[$i]['AchievementCondition']['category'] == 'danSolve1d') { |
| 1591 | $ac1['1d'] = $ac[$i]['AchievementCondition']['value']; |
| 1592 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'danSolve2d') { |
| 1593 | $ac1['2d'] = $ac[$i]['AchievementCondition']['value']; |
| 1594 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'danSolve3d') { |
| 1595 | $ac1['3d'] = $ac[$i]['AchievementCondition']['value']; |
| 1596 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'danSolve4d') { |
| 1597 | $ac1['4d'] = $ac[$i]['AchievementCondition']['value']; |
| 1598 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'danSolve5d') { |
| 1599 | $ac1['5d'] = $ac[$i]['AchievementCondition']['value']; |
| 1600 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'emerald') { |
| 1601 | $ac1['emerald'] = $ac[$i]['AchievementCondition']['value']; |
| 1602 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'sapphire') { |
| 1603 | $ac1['sapphire'] = $ac[$i]['AchievementCondition']['value']; |
| 1604 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'ruby') { |
| 1605 | $ac1['ruby'] = $ac[$i]['AchievementCondition']['value']; |
| 1606 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'sprint') { |
| 1607 | $ac1['sprint'] = $ac[$i]['AchievementCondition']['value']; |
| 1608 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'golden') { |
| 1609 | $ac1['golden'] = $ac[$i]['AchievementCondition']['value']; |
| 1610 | } elseif ($ac[$i]['AchievementCondition']['category'] == 'potion') { |
| 1611 | $ac1['potion'] = $ac[$i]['AchievementCondition']['value']; |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | $existingAs = []; |
| 1616 | $bufferCount = count($buffer); |
| 1617 | for ($i = 0; $i < $bufferCount; $i++) { |
| 1618 | $existingAs[$buffer[$i]['AchievementStatus']['achievement_id']] = $buffer[$i]; |
| 1619 | } |
| 1620 | $as = []; |
| 1621 | $as['AchievementStatus']['user_id'] = Auth::getUserID(); |
| 1622 | $updated = []; |
| 1623 | $achievementId = 101; |
| 1624 | if ($ac1['1d'] > 0 && !isset($existingAs[$achievementId])) { |
| 1625 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1626 | ClassRegistry::init('AchievementStatus')->create(); |
| 1627 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1628 | array_push($updated, $achievementId); |
| 1629 | } |
| 1630 | $achievementId = 102; |
| 1631 | if ($ac1['2d'] > 0 && !isset($existingAs[$achievementId])) { |
| 1632 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1633 | ClassRegistry::init('AchievementStatus')->create(); |
| 1634 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1635 | array_push($updated, $achievementId); |
| 1636 | } |
| 1637 | $achievementId = 103; |
| 1638 | if ($ac1['3d'] > 0 && !isset($existingAs[$achievementId])) { |
| 1639 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1640 | ClassRegistry::init('AchievementStatus')->create(); |
| 1641 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1642 | array_push($updated, $achievementId); |
| 1643 | } |
| 1644 | $achievementId = 104; |
| 1645 | if ($ac1['4d'] > 0 && !isset($existingAs[$achievementId])) { |
| 1646 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1647 | ClassRegistry::init('AchievementStatus')->create(); |
| 1648 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1649 | array_push($updated, $achievementId); |
| 1650 | } |
| 1651 | $achievementId = 105; |
| 1652 | if ($ac1['5d'] > 0 && !isset($existingAs[$achievementId])) { |
| 1653 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1654 | ClassRegistry::init('AchievementStatus')->create(); |
| 1655 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1656 | array_push($updated, $achievementId); |
| 1657 | } |
| 1658 | $achievementId = 106; |
| 1659 | if ($ac1['1d'] >= 10 && !isset($existingAs[$achievementId])) { |
| 1660 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1661 | ClassRegistry::init('AchievementStatus')->create(); |
| 1662 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1663 | array_push($updated, $achievementId); |
| 1664 | } |
| 1665 | $achievementId = 107; |
| 1666 | if ($ac1['2d'] >= 10 && !isset($existingAs[$achievementId])) { |
| 1667 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1668 | ClassRegistry::init('AchievementStatus')->create(); |
| 1669 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1670 | array_push($updated, $achievementId); |
| 1671 | } |
| 1672 | $achievementId = 108; |
| 1673 | if ($ac1['3d'] >= 10 && !isset($existingAs[$achievementId])) { |
| 1674 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1675 | ClassRegistry::init('AchievementStatus')->create(); |
| 1676 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1677 | array_push($updated, $achievementId); |
| 1678 | } |
| 1679 | $achievementId = 109; |
| 1680 | if ($ac1['4d'] >= 10 && !isset($existingAs[$achievementId])) { |
| 1681 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1682 | ClassRegistry::init('AchievementStatus')->create(); |
| 1683 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1684 | array_push($updated, $achievementId); |
| 1685 | } |
| 1686 | $achievementId = 110; |
| 1687 | if ($ac1['5d'] >= 10 && !isset($existingAs[$achievementId])) { |
| 1688 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1689 | ClassRegistry::init('AchievementStatus')->create(); |
| 1690 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1691 | array_push($updated, $achievementId); |
| 1692 | } |
| 1693 | $achievementId = 111; |
| 1694 | if (isset($ac1['emerald'])) { |
| 1695 | if ($ac1['emerald'] == 1 && !isset($existingAs[$achievementId])) { |
| 1696 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1697 | ClassRegistry::init('AchievementStatus')->create(); |
| 1698 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1699 | array_push($updated, $achievementId); |
| 1700 | } |
| 1701 | } |
| 1702 | $achievementId = 112; |
| 1703 | if (isset($ac1['sapphire'])) { |
| 1704 | if ($ac1['sapphire'] == 1 && !isset($existingAs[$achievementId])) { |
| 1705 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1706 | ClassRegistry::init('AchievementStatus')->create(); |
| 1707 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1708 | array_push($updated, $achievementId); |
| 1709 | } |
| 1710 | } |
| 1711 | $achievementId = 113; |
| 1712 | if (isset($ac1['ruby'])) { |
| 1713 | if ($ac1['ruby'] == 1 && !isset($existingAs[$achievementId])) { |
| 1714 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1715 | ClassRegistry::init('AchievementStatus')->create(); |
| 1716 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1717 | array_push($updated, $achievementId); |
| 1718 | } |
| 1719 | } |
| 1720 | $achievementId = 114; |
| 1721 | if (!isset($existingAs[$achievementId]) && isset($existingAs[111]) && isset($existingAs[112]) && isset($existingAs[113])) { |
| 1722 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1723 | ClassRegistry::init('AchievementStatus')->create(); |
| 1724 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1725 | array_push($updated, $achievementId); |
| 1726 | } |
| 1727 | $achievementId = 96; |
| 1728 | if (!isset($existingAs[$achievementId]) && $ac1['sprint'] >= 30) { |
| 1729 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1730 | ClassRegistry::init('AchievementStatus')->create(); |
| 1731 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1732 | array_push($updated, $achievementId); |
| 1733 | } |
| 1734 | $achievementId = 97; |
| 1735 | if (!isset($existingAs[$achievementId]) && $ac1['golden'] >= 10) { |
| 1736 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1737 | ClassRegistry::init('AchievementStatus')->create(); |
| 1738 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1739 | array_push($updated, $achievementId); |
| 1740 | } |
| 1741 | $achievementId = 98; |
| 1742 | if (!isset($existingAs[$achievementId]) && $ac1['potion'] >= 1) { |
| 1743 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1744 | ClassRegistry::init('AchievementStatus')->create(); |
| 1745 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1746 | array_push($updated, $achievementId); |
| 1747 | } |
| 1748 | $updatedCount = count($updated); |
| 1749 | for ($i = 0; $i < $updatedCount; $i++) { |
| 1750 | $a = ClassRegistry::init('Achievement')->findById($updated[$i]); |
| 1751 | $updated[$i] = []; |
| 1752 | $updated[$i][0] = $a['Achievement']['name']; |
| 1753 | $updated[$i][1] = $a['Achievement']['description']; |
| 1754 | $updated[$i][2] = $a['Achievement']['image']; |
| 1755 | $updated[$i][3] = $a['Achievement']['color']; |
| 1756 | $updated[$i][4] = $a['Achievement']['xp']; |
| 1757 | $updated[$i][5] = $a['Achievement']['id']; |
| 1758 | } |
| 1759 | |
| 1760 | return $updated; |
| 1761 | } |
| 1762 | } |
| 1763 | |
| 1764 | protected function checkForLocked($t, $setsWithPremium) { |
| 1765 | $scCheck = $this->SetConnection->find('first', ['conditions' => ['tsumego_id' => $t['Tsumego']['id']]]); |
| 1766 | if ($scCheck && in_array($scCheck['SetConnection']['set_id'], $setsWithPremium) && !Auth::hasPremium()) { |
| 1767 | $t['Tsumego']['locked'] = true; |
| 1768 | } else { |
| 1769 | $t['Tsumego']['locked'] = false; |
| 1770 | } |
| 1771 | |
| 1772 | return $t; |
| 1773 | } |
| 1774 | public static function checkNoErrorAchievements() { |
| 1775 | if (Auth::isLoggedIn()) { |
| 1776 | |
| 1777 | $ac = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 1778 | 'order' => 'value DESC', |
| 1779 | 'conditions' => [ |
| 1780 | 'user_id' => Auth::getUserID(), |
| 1781 | 'category' => 'err', |
| 1782 | ], |
| 1783 | ]); |
| 1784 | |
| 1785 | $buffer = ClassRegistry::init('AchievementStatus')->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 1786 | if (!$buffer) { |
| 1787 | $buffer = []; |
| 1788 | } |
| 1789 | $existingAs = []; |
| 1790 | $bufferCount = count($buffer); |
| 1791 | for ($i = 0; $i < $bufferCount; $i++) { |
| 1792 | $existingAs[$buffer[$i]['AchievementStatus']['achievement_id']] = $buffer[$i]; |
| 1793 | } |
| 1794 | $as = []; |
| 1795 | $as['AchievementStatus']['user_id'] = Auth::getUserID(); |
| 1796 | $updated = []; |
| 1797 | |
| 1798 | $achievementId = 53; |
| 1799 | if ($ac['AchievementCondition']['value'] >= 10 && !isset($existingAs[$achievementId])) { |
| 1800 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1801 | ClassRegistry::init('AchievementStatus')->create(); |
| 1802 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1803 | array_push($updated, $achievementId); |
| 1804 | } |
| 1805 | $achievementId = 54; |
| 1806 | if ($ac['AchievementCondition']['value'] >= 20 && !isset($existingAs[$achievementId])) { |
| 1807 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1808 | ClassRegistry::init('AchievementStatus')->create(); |
| 1809 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1810 | array_push($updated, $achievementId); |
| 1811 | } |
| 1812 | $achievementId = 55; |
| 1813 | if ($ac['AchievementCondition']['value'] >= 30 && !isset($existingAs[$achievementId])) { |
| 1814 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1815 | ClassRegistry::init('AchievementStatus')->create(); |
| 1816 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1817 | array_push($updated, $achievementId); |
| 1818 | } |
| 1819 | $achievementId = 56; |
| 1820 | if ($ac['AchievementCondition']['value'] >= 50 && !isset($existingAs[$achievementId])) { |
| 1821 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1822 | ClassRegistry::init('AchievementStatus')->create(); |
| 1823 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1824 | array_push($updated, $achievementId); |
| 1825 | } |
| 1826 | $achievementId = 57; |
| 1827 | if ($ac['AchievementCondition']['value'] >= 100 && !isset($existingAs[$achievementId])) { |
| 1828 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1829 | ClassRegistry::init('AchievementStatus')->create(); |
| 1830 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1831 | array_push($updated, $achievementId); |
| 1832 | } |
| 1833 | $achievementId = 58; |
| 1834 | if ($ac['AchievementCondition']['value'] >= 200 && !isset($existingAs[$achievementId])) { |
| 1835 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1836 | ClassRegistry::init('AchievementStatus')->create(); |
| 1837 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1838 | array_push($updated, $achievementId); |
| 1839 | } |
| 1840 | $updatedCount = count($updated); |
| 1841 | for ($i = 0; $i < $updatedCount; $i++) { |
| 1842 | $a = ClassRegistry::init('Achievement')->findById($updated[$i]); |
| 1843 | $updated[$i] = []; |
| 1844 | $updated[$i][0] = $a['Achievement']['name']; |
| 1845 | $updated[$i][1] = $a['Achievement']['description']; |
| 1846 | $updated[$i][2] = $a['Achievement']['image']; |
| 1847 | $updated[$i][3] = $a['Achievement']['color']; |
| 1848 | $updated[$i][4] = $a['Achievement']['xp']; |
| 1849 | $updated[$i][5] = $a['Achievement']['id']; |
| 1850 | } |
| 1851 | |
| 1852 | return $updated; |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | protected function checkTimeModeAchievements() { |
| 1857 | $this->loadModel('Achievement'); |
| 1858 | $this->loadModel('AchievementStatus'); |
| 1859 | $this->loadModel('TimeModeSession'); |
| 1860 | |
| 1861 | $buffer = ClassRegistry::init('AchievementStatus')->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 1862 | if (!$buffer) { |
| 1863 | $buffer = []; |
| 1864 | } |
| 1865 | $existingAs = []; |
| 1866 | $bufferCount = count($buffer); |
| 1867 | for ($i = 0; $i < $bufferCount; $i++) { |
| 1868 | $existingAs[$buffer[$i]['AchievementStatus']['achievement_id']] = $buffer[$i]; |
| 1869 | } |
| 1870 | $as = []; |
| 1871 | $as['AchievementStatus']['user_id'] = Auth::getUserID(); |
| 1872 | $updated = []; |
| 1873 | |
| 1874 | $rBlitz = $this->TimeModeSession->find('all', ['conditions' => ['time_mode_category_id' => TimeModeUtil::$CATEGORY_BLITZ, 'user_id' => Auth::getUserID()]]); |
| 1875 | if (!$rBlitz) { |
| 1876 | $rBlitz = []; |
| 1877 | } |
| 1878 | $rFast = $this->TimeModeSession->find('all', ['conditions' => ['time_mode_category_id' => TimeModeUtil::$CATEGORY_FAST_SPEED, 'user_id' => Auth::getUserID()]]); |
| 1879 | if (!$rFast) { |
| 1880 | $rFast = []; |
| 1881 | } |
| 1882 | $rSlow = $this->TimeModeSession->find('all', ['conditions' => ['time_mode_category_id' => TimeModeUtil::$CATEGORY_SLOW_SPEED, 'user_id' => Auth::getUserID()]]); |
| 1883 | if (!$rSlow) { |
| 1884 | $rSlow = []; |
| 1885 | } |
| 1886 | $r = $this->TimeModeSession->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 1887 | if (!$r) { |
| 1888 | $r = []; |
| 1889 | } |
| 1890 | |
| 1891 | $timeModeAchievements = []; |
| 1892 | for ($i = 70; $i <= 91; $i++) { |
| 1893 | $timeModeAchievements[$i] = false; |
| 1894 | } |
| 1895 | $rCount = count($r); |
| 1896 | for ($i = 0; $i < $rCount; $i++) { |
| 1897 | if ($r[$i]['TimeModeSession']['status'] == 's') { |
| 1898 | if ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '5k') { |
| 1899 | if ($r[$i]['TimeModeSession']['mode'] == 2) { |
| 1900 | $timeModeAchievements[70] = true; |
| 1901 | } elseif ($r[$i]['TimeModeSession']['mode'] == 1) { |
| 1902 | $timeModeAchievements[76] = true; |
| 1903 | } elseif ($r[$i]['TimeModeSession']['mode'] == 0) { |
| 1904 | $timeModeAchievements[82] = true; |
| 1905 | } |
| 1906 | } elseif ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '4k') { |
| 1907 | if ($r[$i]['TimeModeSession']['mode'] == 2) { |
| 1908 | $timeModeAchievements[71] = true; |
| 1909 | } elseif ($r[$i]['TimeModeSession']['mode'] == 1) { |
| 1910 | $timeModeAchievements[77] = true; |
| 1911 | } elseif ($r[$i]['TimeModeSession']['mode'] == 0) { |
| 1912 | $timeModeAchievements[83] = true; |
| 1913 | } |
| 1914 | } elseif ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '3k') { |
| 1915 | if ($r[$i]['TimeModeSession']['mode'] == 2) { |
| 1916 | $timeModeAchievements[72] = true; |
| 1917 | } elseif ($r[$i]['TimeModeSession']['mode'] == 1) { |
| 1918 | $timeModeAchievements[78] = true; |
| 1919 | } elseif ($r[$i]['TimeModeSession']['mode'] == 0) { |
| 1920 | $timeModeAchievements[84] = true; |
| 1921 | } |
| 1922 | } elseif ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '2k') { |
| 1923 | if ($r[$i]['TimeModeSession']['mode'] == 2) { |
| 1924 | $timeModeAchievements[73] = true; |
| 1925 | } elseif ($r[$i]['TimeModeSession']['mode'] == 1) { |
| 1926 | $timeModeAchievements[79] = true; |
| 1927 | } elseif ($r[$i]['TimeModeSession']['mode'] == 0) { |
| 1928 | $timeModeAchievements[85] = true; |
| 1929 | } |
| 1930 | } elseif ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '1k') { |
| 1931 | if ($r[$i]['TimeModeSession']['mode'] == 2) { |
| 1932 | $timeModeAchievements[74] = true; |
| 1933 | } elseif ($r[$i]['TimeModeSession']['mode'] == 1) { |
| 1934 | $timeModeAchievements[80] = true; |
| 1935 | } elseif ($r[$i]['TimeModeSession']['mode'] == 0) { |
| 1936 | $timeModeAchievements[86] = true; |
| 1937 | } |
| 1938 | } elseif ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '1d') { |
| 1939 | if ($r[$i]['TimeModeSession']['mode'] == 2) { |
| 1940 | $timeModeAchievements[75] = true; |
| 1941 | } elseif ($r[$i]['TimeModeSession']['mode'] == 1) { |
| 1942 | $timeModeAchievements[81] = true; |
| 1943 | } elseif ($r[$i]['TimeModeSession']['mode'] == 0) { |
| 1944 | $timeModeAchievements[87] = true; |
| 1945 | } |
| 1946 | } |
| 1947 | } |
| 1948 | if ($r[$i]['TimeModeSession']['points'] >= 850 |
| 1949 | && ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '4k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '3k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '2k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '1k' |
| 1950 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '1d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '2d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '3d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '4d' |
| 1951 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '5d')) { |
| 1952 | $timeModeAchievements[91] = true; |
| 1953 | } |
| 1954 | if ($r[$i]['TimeModeSession']['points'] >= 875 |
| 1955 | && ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '4k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '3k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '2k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '1k' |
| 1956 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '1d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '2d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '3d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '4d' |
| 1957 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '5d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '5k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '6k')) { |
| 1958 | $timeModeAchievements[90] = true; |
| 1959 | } |
| 1960 | if ($r[$i]['TimeModeSession']['points'] >= 900 |
| 1961 | && ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '4k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '3k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '2k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '1k' |
| 1962 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '1d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '2d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '3d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '4d' |
| 1963 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '5d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '5k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '6k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '7k' |
| 1964 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '8k')) { |
| 1965 | $timeModeAchievements[89] = true; |
| 1966 | } |
| 1967 | if ($r[$i]['TimeModeSession']['points'] >= 950 |
| 1968 | && ($r[$i]['TimeModeSession']['TimeModeAttempt'] == '4k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '3k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '2k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '1k' |
| 1969 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '1d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '2d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '3d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '4d' |
| 1970 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '5d' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '5k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '6k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '7k' |
| 1971 | || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '8k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '9k' || $r[$i]['TimeModeSession']['TimeModeAttempt'] == '10k')) { |
| 1972 | $timeModeAchievements[88] = true; |
| 1973 | } |
| 1974 | } |
| 1975 | for ($i = 70; $i <= 91; $i++) { |
| 1976 | $achievementId = $i; |
| 1977 | if ($timeModeAchievements[$achievementId] == true && !isset($existingAs[$achievementId])) { |
| 1978 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 1979 | ClassRegistry::init('AchievementStatus')->create(); |
| 1980 | ClassRegistry::init('AchievementStatus')->save($as); |
| 1981 | array_push($updated, $achievementId); |
| 1982 | } |
| 1983 | } |
| 1984 | $updatedCount = count($updated); |
| 1985 | for ($i = 0; $i < $updatedCount; $i++) { |
| 1986 | $a = ClassRegistry::init('Achievement')->findById($updated[$i]); |
| 1987 | $updated[$i] = []; |
| 1988 | $updated[$i][0] = $a['Achievement']['name']; |
| 1989 | $updated[$i][1] = $a['Achievement']['description']; |
| 1990 | $updated[$i][2] = $a['Achievement']['image']; |
| 1991 | $updated[$i][3] = $a['Achievement']['color']; |
| 1992 | $updated[$i][4] = $a['Achievement']['xp']; |
| 1993 | $updated[$i][5] = $a['Achievement']['id']; |
| 1994 | } |
| 1995 | |
| 1996 | return $updated; |
| 1997 | } |
| 1998 | |
| 1999 | public static function checkRatingAchievements() { |
| 2000 | if (!Auth::isLoggedIn()) { |
| 2001 | return; |
| 2002 | } |
| 2003 | |
| 2004 | $buffer = ClassRegistry::init('AchievementStatus')->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 2005 | if (!$buffer) { |
| 2006 | $buffer = []; |
| 2007 | } |
| 2008 | $existingAs = []; |
| 2009 | $bufferCount = count($buffer); |
| 2010 | for ($i = 0; $i < $bufferCount; $i++) { |
| 2011 | $existingAs[$buffer[$i]['AchievementStatus']['achievement_id']] = $buffer[$i]; |
| 2012 | } |
| 2013 | $as = []; |
| 2014 | $as['AchievementStatus']['user_id'] = Auth::getUserID(); |
| 2015 | $updated = []; |
| 2016 | |
| 2017 | $achievementId = 59; |
| 2018 | $currentElo = Auth::getUser()['rating']; |
| 2019 | if ($currentElo >= 1500 && !isset($existingAs[$achievementId])) { |
| 2020 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2021 | ClassRegistry::init('AchievementStatus')->create(); |
| 2022 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2023 | array_push($updated, $achievementId); |
| 2024 | } |
| 2025 | $achievementId = 60; |
| 2026 | if ($currentElo >= 1600 && !isset($existingAs[$achievementId])) { |
| 2027 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2028 | ClassRegistry::init('AchievementStatus')->create(); |
| 2029 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2030 | array_push($updated, $achievementId); |
| 2031 | } |
| 2032 | $achievementId = 61; |
| 2033 | if ($currentElo >= 1700 && !isset($existingAs[$achievementId])) { |
| 2034 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2035 | ClassRegistry::init('AchievementStatus')->create(); |
| 2036 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2037 | array_push($updated, $achievementId); |
| 2038 | } |
| 2039 | $achievementId = 62; |
| 2040 | if ($currentElo >= 1800 && !isset($existingAs[$achievementId])) { |
| 2041 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2042 | ClassRegistry::init('AchievementStatus')->create(); |
| 2043 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2044 | array_push($updated, $achievementId); |
| 2045 | } |
| 2046 | $achievementId = 63; |
| 2047 | if ($currentElo >= 1900 && !isset($existingAs[$achievementId])) { |
| 2048 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2049 | ClassRegistry::init('AchievementStatus')->create(); |
| 2050 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2051 | array_push($updated, $achievementId); |
| 2052 | } |
| 2053 | $achievementId = 64; |
| 2054 | if ($currentElo >= 2000 && !isset($existingAs[$achievementId])) { |
| 2055 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2056 | ClassRegistry::init('AchievementStatus')->create(); |
| 2057 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2058 | array_push($updated, $achievementId); |
| 2059 | } |
| 2060 | $achievementId = 65; |
| 2061 | if ($currentElo >= 2100 && !isset($existingAs[$achievementId])) { |
| 2062 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2063 | ClassRegistry::init('AchievementStatus')->create(); |
| 2064 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2065 | array_push($updated, $achievementId); |
| 2066 | } |
| 2067 | $achievementId = 66; |
| 2068 | if ($currentElo >= 2200 && !isset($existingAs[$achievementId])) { |
| 2069 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2070 | ClassRegistry::init('AchievementStatus')->create(); |
| 2071 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2072 | array_push($updated, $achievementId); |
| 2073 | } |
| 2074 | $achievementId = 67; |
| 2075 | if ($currentElo >= 2300 && !isset($existingAs[$achievementId])) { |
| 2076 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2077 | ClassRegistry::init('AchievementStatus')->create(); |
| 2078 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2079 | array_push($updated, $achievementId); |
| 2080 | } |
| 2081 | $achievementId = 68; |
| 2082 | if ($currentElo >= 2400 && !isset($existingAs[$achievementId])) { |
| 2083 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2084 | ClassRegistry::init('AchievementStatus')->create(); |
| 2085 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2086 | array_push($updated, $achievementId); |
| 2087 | } |
| 2088 | $achievementId = 69; |
| 2089 | if ($currentElo >= 2500 && !isset($existingAs[$achievementId])) { |
| 2090 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2091 | ClassRegistry::init('AchievementStatus')->create(); |
| 2092 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2093 | array_push($updated, $achievementId); |
| 2094 | } |
| 2095 | $updatedCount = count($updated); |
| 2096 | for ($i = 0; $i < $updatedCount; $i++) { |
| 2097 | $a = ClassRegistry::init('Achievement')->findById($updated[$i]); |
| 2098 | $updated[$i] = []; |
| 2099 | $updated[$i][0] = $a['Achievement']['name']; |
| 2100 | $updated[$i][1] = $a['Achievement']['description']; |
| 2101 | $updated[$i][2] = $a['Achievement']['image']; |
| 2102 | $updated[$i][3] = $a['Achievement']['color']; |
| 2103 | $updated[$i][4] = $a['Achievement']['xp']; |
| 2104 | $updated[$i][5] = $a['Achievement']['id']; |
| 2105 | } |
| 2106 | |
| 2107 | return $updated; |
| 2108 | } |
| 2109 | |
| 2110 | public static function checkLevelAchievements() { |
| 2111 | if (!Auth::isLoggedIn()) { |
| 2112 | return; |
| 2113 | } |
| 2114 | $buffer = ClassRegistry::init('AchievementStatus')->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 2115 | if (!$buffer) { |
| 2116 | $buffer = []; |
| 2117 | } |
| 2118 | $existingAs = []; |
| 2119 | $bufferCount = count($buffer); |
| 2120 | for ($i = 0; $i < $bufferCount; $i++) { |
| 2121 | $existingAs[$buffer[$i]['AchievementStatus']['achievement_id']] = $buffer[$i]; |
| 2122 | } |
| 2123 | $as = []; |
| 2124 | $as['AchievementStatus']['user_id'] = Auth::getUserID(); |
| 2125 | $updated = []; |
| 2126 | |
| 2127 | $achievementId = 36; |
| 2128 | $userLevel = Auth::getUser()['level']; |
| 2129 | if ($userLevel >= 10 && !isset($existingAs[$achievementId])) { |
| 2130 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2131 | ClassRegistry::init('AchievementStatus')->create(); |
| 2132 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2133 | array_push($updated, $achievementId); |
| 2134 | } |
| 2135 | $achievementId = 37; |
| 2136 | if ($userLevel >= 20 && !isset($existingAs[$achievementId])) { |
| 2137 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2138 | ClassRegistry::init('AchievementStatus')->create(); |
| 2139 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2140 | array_push($updated, $achievementId); |
| 2141 | } |
| 2142 | $achievementId = 38; |
| 2143 | if ($userLevel >= 30 && !isset($existingAs[$achievementId])) { |
| 2144 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2145 | ClassRegistry::init('AchievementStatus')->create(); |
| 2146 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2147 | array_push($updated, $achievementId); |
| 2148 | } |
| 2149 | $achievementId = 39; |
| 2150 | if ($userLevel >= 40 && !isset($existingAs[$achievementId])) { |
| 2151 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2152 | ClassRegistry::init('AchievementStatus')->create(); |
| 2153 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2154 | array_push($updated, $achievementId); |
| 2155 | } |
| 2156 | $achievementId = 40; |
| 2157 | if ($userLevel >= 50 && !isset($existingAs[$achievementId])) { |
| 2158 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2159 | ClassRegistry::init('AchievementStatus')->create(); |
| 2160 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2161 | array_push($updated, $achievementId); |
| 2162 | } |
| 2163 | $achievementId = 41; |
| 2164 | if ($userLevel >= 60 && !isset($existingAs[$achievementId])) { |
| 2165 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2166 | ClassRegistry::init('AchievementStatus')->create(); |
| 2167 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2168 | array_push($updated, $achievementId); |
| 2169 | } |
| 2170 | $achievementId = 42; |
| 2171 | if ($userLevel >= 70 && !isset($existingAs[$achievementId])) { |
| 2172 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2173 | ClassRegistry::init('AchievementStatus')->create(); |
| 2174 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2175 | array_push($updated, $achievementId); |
| 2176 | } |
| 2177 | $achievementId = 43; |
| 2178 | if ($userLevel >= 80 && !isset($existingAs[$achievementId])) { |
| 2179 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2180 | ClassRegistry::init('AchievementStatus')->create(); |
| 2181 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2182 | array_push($updated, $achievementId); |
| 2183 | } |
| 2184 | $achievementId = 44; |
| 2185 | if ($userLevel >= 90 && !isset($existingAs[$achievementId])) { |
| 2186 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2187 | ClassRegistry::init('AchievementStatus')->create(); |
| 2188 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2189 | array_push($updated, $achievementId); |
| 2190 | } |
| 2191 | $achievementId = 45; |
| 2192 | if ($userLevel >= 100 && !isset($existingAs[$achievementId])) { |
| 2193 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2194 | ClassRegistry::init('AchievementStatus')->create(); |
| 2195 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2196 | array_push($updated, $achievementId); |
| 2197 | } |
| 2198 | $achievementId = 100; |
| 2199 | if (Auth::hasPremium() && !isset($existingAs[$achievementId])) { |
| 2200 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2201 | ClassRegistry::init('AchievementStatus')->create(); |
| 2202 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2203 | array_push($updated, $achievementId); |
| 2204 | } |
| 2205 | $updatedCount = count($updated); |
| 2206 | for ($i = 0; $i < $updatedCount; $i++) { |
| 2207 | $a = ClassRegistry::init('Achievement')->findById($updated[$i]); |
| 2208 | $updated[$i] = []; |
| 2209 | $updated[$i][0] = $a['Achievement']['name']; |
| 2210 | $updated[$i][1] = $a['Achievement']['description']; |
| 2211 | $updated[$i][2] = $a['Achievement']['image']; |
| 2212 | $updated[$i][3] = $a['Achievement']['color']; |
| 2213 | $updated[$i][4] = $a['Achievement']['xp']; |
| 2214 | $updated[$i][5] = $a['Achievement']['id']; |
| 2215 | } |
| 2216 | |
| 2217 | return $updated; |
| 2218 | } |
| 2219 | |
| 2220 | protected function checkSetCompletedAchievements() { |
| 2221 | $this->loadModel('Set'); |
| 2222 | $this->loadModel('Tsumego'); |
| 2223 | $this->loadModel('Achievement'); |
| 2224 | $this->loadModel('AchievementStatus'); |
| 2225 | $this->loadModel('AchievementCondition'); |
| 2226 | |
| 2227 | $ac = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 2228 | 'order' => 'value DESC', |
| 2229 | 'conditions' => [ |
| 2230 | 'user_id' => Auth::getUserID(), |
| 2231 | 'category' => 'set', |
| 2232 | ], |
| 2233 | ]); |
| 2234 | |
| 2235 | if (!$ac) { |
| 2236 | return []; |
| 2237 | } |
| 2238 | |
| 2239 | $buffer = ClassRegistry::init('AchievementStatus')->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 2240 | if (!$buffer) { |
| 2241 | $buffer = []; |
| 2242 | } |
| 2243 | $existingAs = []; |
| 2244 | $bufferCount = count($buffer); |
| 2245 | for ($i = 0; $i < $bufferCount; $i++) { |
| 2246 | $existingAs[$buffer[$i]['AchievementStatus']['achievement_id']] = $buffer[$i]; |
| 2247 | } |
| 2248 | $as = []; |
| 2249 | $as['AchievementStatus']['user_id'] = Auth::getUserID(); |
| 2250 | $updated = []; |
| 2251 | |
| 2252 | $achievementId = 47; |
| 2253 | if ($ac['AchievementCondition']['value'] >= 10 && !isset($existingAs[$achievementId])) { |
| 2254 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2255 | ClassRegistry::init('AchievementStatus')->create(); |
| 2256 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2257 | array_push($updated, $achievementId); |
| 2258 | } |
| 2259 | $achievementId = 48; |
| 2260 | if ($ac['AchievementCondition']['value'] >= 20 && !isset($existingAs[$achievementId])) { |
| 2261 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2262 | ClassRegistry::init('AchievementStatus')->create(); |
| 2263 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2264 | array_push($updated, $achievementId); |
| 2265 | } |
| 2266 | $achievementId = 49; |
| 2267 | if ($ac['AchievementCondition']['value'] >= 30 && !isset($existingAs[$achievementId])) { |
| 2268 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2269 | ClassRegistry::init('AchievementStatus')->create(); |
| 2270 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2271 | array_push($updated, $achievementId); |
| 2272 | } |
| 2273 | $achievementId = 50; |
| 2274 | if ($ac['AchievementCondition']['value'] >= 40 && !isset($existingAs[$achievementId])) { |
| 2275 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2276 | ClassRegistry::init('AchievementStatus')->create(); |
| 2277 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2278 | array_push($updated, $achievementId); |
| 2279 | } |
| 2280 | $achievementId = 51; |
| 2281 | if ($ac['AchievementCondition']['value'] >= 50 && !isset($existingAs[$achievementId])) { |
| 2282 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2283 | ClassRegistry::init('AchievementStatus')->create(); |
| 2284 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2285 | array_push($updated, $achievementId); |
| 2286 | } |
| 2287 | $achievementId = 52; |
| 2288 | if ($ac['AchievementCondition']['value'] >= 60 && !isset($existingAs[$achievementId])) { |
| 2289 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2290 | ClassRegistry::init('AchievementStatus')->create(); |
| 2291 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2292 | array_push($updated, $achievementId); |
| 2293 | } |
| 2294 | $updatedCount = count($updated); |
| 2295 | for ($i = 0; $i < $updatedCount; $i++) { |
| 2296 | $a = ClassRegistry::init('Achievement')->findById($updated[$i]); |
| 2297 | $updated[$i] = []; |
| 2298 | $updated[$i][0] = $a['Achievement']['name']; |
| 2299 | $updated[$i][1] = $a['Achievement']['description']; |
| 2300 | $updated[$i][2] = $a['Achievement']['image']; |
| 2301 | $updated[$i][3] = $a['Achievement']['color']; |
| 2302 | $updated[$i][4] = $a['Achievement']['xp']; |
| 2303 | $updated[$i][5] = $a['Achievement']['id']; |
| 2304 | } |
| 2305 | |
| 2306 | return $updated; |
| 2307 | } |
| 2308 | |
| 2309 | protected function setAchievementSpecial($s = null) { |
| 2310 | $this->loadModel('Set'); |
| 2311 | $this->loadModel('Tsumego'); |
| 2312 | $this->loadModel('TsumegoStatus'); |
| 2313 | $this->loadModel('Achievement'); |
| 2314 | $this->loadModel('AchievementStatus'); |
| 2315 | $this->loadModel('SetConnection'); |
| 2316 | |
| 2317 | $buffer = ClassRegistry::init('AchievementStatus')->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 2318 | if (!$buffer) { |
| 2319 | $buffer = []; |
| 2320 | } |
| 2321 | $existingAs = []; |
| 2322 | $bufferCount = count($buffer); |
| 2323 | for ($i = 0; $i < $bufferCount; $i++) { |
| 2324 | $existingAs[$buffer[$i]['AchievementStatus']['achievement_id']] = $buffer[$i]; |
| 2325 | } |
| 2326 | $as = []; |
| 2327 | $as['AchievementStatus']['user_id'] = Auth::getUserID(); |
| 2328 | $updated = []; |
| 2329 | |
| 2330 | $tsIds = []; |
| 2331 | $completed = ''; |
| 2332 | if ($s == 'cc1') { |
| 2333 | $ts1 = TsumegoUtil::collectTsumegosFromSet(50); |
| 2334 | $ts2 = TsumegoUtil::collectTsumegosFromSet(52); |
| 2335 | $ts3 = TsumegoUtil::collectTsumegosFromSet(53); |
| 2336 | $ts4 = TsumegoUtil::collectTsumegosFromSet(54); |
| 2337 | $ts = array_merge($ts1, $ts2, $ts3, $ts4); |
| 2338 | $tsCount = count($ts); |
| 2339 | for ($i = 0; $i < $tsCount; $i++) { |
| 2340 | array_push($tsIds, $ts[$i]['Tsumego']['id']); |
| 2341 | } |
| 2342 | $uts = $this->TsumegoStatus->find('all', [ |
| 2343 | 'conditions' => [ |
| 2344 | 'user_id' => Auth::getUserID(), |
| 2345 | 'tsumego_id' => $tsIds, |
| 2346 | ], |
| 2347 | ]); |
| 2348 | if (!$uts) { |
| 2349 | $uts = []; |
| 2350 | } |
| 2351 | $counter = 0; |
| 2352 | $utsCount = count($uts); |
| 2353 | for ($j = 0; $j < $utsCount; $j++) { |
| 2354 | for ($k = 0; $k < $tsCount; $k++) { |
| 2355 | if ($uts[$j]['TsumegoStatus']['tsumego_id'] == $ts[$k]['Tsumego']['id'] && ($uts[$j]['TsumegoStatus']['status'] == 'S' |
| 2356 | || $uts[$j]['TsumegoStatus']['status'] == 'W' || $uts[$j]['TsumegoStatus']['status'] == 'C')) { |
| 2357 | $counter++; |
| 2358 | } |
| 2359 | } |
| 2360 | } |
| 2361 | if ($counter == count($ts)) { |
| 2362 | $completed = $s; |
| 2363 | } |
| 2364 | } elseif ($s == 'cc2') { |
| 2365 | $ts1 = TsumegoUtil::collectTsumegosFromSet(41); |
| 2366 | $ts2 = TsumegoUtil::collectTsumegosFromSet(49); |
| 2367 | $ts3 = TsumegoUtil::collectTsumegosFromSet(65); |
| 2368 | $ts4 = TsumegoUtil::collectTsumegosFromSet(66); |
| 2369 | $ts = array_merge($ts1, $ts2, $ts3, $ts4); |
| 2370 | $tsCount = count($ts); |
| 2371 | for ($i = 0; $i < $tsCount; $i++) { |
| 2372 | array_push($tsIds, $ts[$i]['Tsumego']['id']); |
| 2373 | } |
| 2374 | $uts = $this->TsumegoStatus->find('all', [ |
| 2375 | 'conditions' => [ |
| 2376 | 'user_id' => Auth::getUserID(), |
| 2377 | 'tsumego_id' => $tsIds, |
| 2378 | ], |
| 2379 | ]); |
| 2380 | if (!$uts) { |
| 2381 | $uts = []; |
| 2382 | } |
| 2383 | $counter = 0; |
| 2384 | $utsCount = count($uts); |
| 2385 | for ($j = 0; $j < $utsCount; $j++) { |
| 2386 | for ($k = 0; $k < $tsCount; $k++) { |
| 2387 | if ($uts[$j]['TsumegoStatus']['tsumego_id'] == $ts[$k]['Tsumego']['id'] && ($uts[$j]['TsumegoStatus']['status'] == 'S' |
| 2388 | || $uts[$j]['TsumegoStatus']['status'] == 'W' || $uts[$j]['TsumegoStatus']['status'] == 'C')) { |
| 2389 | $counter++; |
| 2390 | } |
| 2391 | } |
| 2392 | } |
| 2393 | if ($counter == count($ts)) { |
| 2394 | $completed = $s; |
| 2395 | } |
| 2396 | } elseif ($s == 'cc3') { |
| 2397 | $ts1 = TsumegoUtil::collectTsumegosFromSet(186); |
| 2398 | $ts2 = TsumegoUtil::collectTsumegosFromSet(187); |
| 2399 | $ts3 = TsumegoUtil::collectTsumegosFromSet(196); |
| 2400 | $ts4 = TsumegoUtil::collectTsumegosFromSet(203); |
| 2401 | $ts = array_merge($ts1, $ts2, $ts3, $ts4); |
| 2402 | $tsCount = count($ts); |
| 2403 | for ($i = 0; $i < $tsCount; $i++) { |
| 2404 | array_push($tsIds, $ts[$i]['Tsumego']['id']); |
| 2405 | } |
| 2406 | $uts = $this->TsumegoStatus->find('all', [ |
| 2407 | 'conditions' => [ |
| 2408 | 'user_id' => Auth::getUserID(), |
| 2409 | 'tsumego_id' => $tsIds, |
| 2410 | ], |
| 2411 | ]); |
| 2412 | if (!$uts) { |
| 2413 | $uts = []; |
| 2414 | } |
| 2415 | $counter = 0; |
| 2416 | $utsCount = count($uts); |
| 2417 | for ($j = 0; $j < $utsCount; $j++) { |
| 2418 | for ($k = 0; $k < $tsCount; $k++) { |
| 2419 | if ($uts[$j]['TsumegoStatus']['tsumego_id'] == $ts[$k]['Tsumego']['id'] && ($uts[$j]['TsumegoStatus']['status'] == 'S' |
| 2420 | || $uts[$j]['TsumegoStatus']['status'] == 'W' || $uts[$j]['TsumegoStatus']['status'] == 'C')) { |
| 2421 | $counter++; |
| 2422 | } |
| 2423 | } |
| 2424 | } |
| 2425 | if ($counter == count($ts)) { |
| 2426 | $completed = $s; |
| 2427 | } |
| 2428 | } elseif ($s == '1000w1') { |
| 2429 | $ts1 = TsumegoUtil::collectTsumegosFromSet(190); |
| 2430 | $ts2 = TsumegoUtil::collectTsumegosFromSet(193); |
| 2431 | $ts3 = TsumegoUtil::collectTsumegosFromSet(198); |
| 2432 | $ts = array_merge($ts1, $ts2, $ts3); |
| 2433 | $tsCount = count($ts); |
| 2434 | for ($i = 0; $i < $tsCount; $i++) { |
| 2435 | array_push($tsIds, $ts[$i]['Tsumego']['id']); |
| 2436 | } |
| 2437 | $uts = $this->TsumegoStatus->find('all', [ |
| 2438 | 'conditions' => [ |
| 2439 | 'user_id' => Auth::getUserID(), |
| 2440 | 'tsumego_id' => $tsIds, |
| 2441 | ], |
| 2442 | ]); |
| 2443 | if (!$uts) { |
| 2444 | $uts = []; |
| 2445 | } |
| 2446 | $counter = 0; |
| 2447 | $utsCount = count($uts); |
| 2448 | for ($j = 0; $j < $utsCount; $j++) { |
| 2449 | for ($k = 0; $k < $tsCount; $k++) { |
| 2450 | if ($uts[$j]['TsumegoStatus']['tsumego_id'] == $ts[$k]['Tsumego']['id'] && ($uts[$j]['TsumegoStatus']['status'] == 'S' |
| 2451 | || $uts[$j]['TsumegoStatus']['status'] == 'W' || $uts[$j]['TsumegoStatus']['status'] == 'C')) { |
| 2452 | $counter++; |
| 2453 | } |
| 2454 | } |
| 2455 | } |
| 2456 | if ($counter == count($ts)) { |
| 2457 | $completed = $s; |
| 2458 | } |
| 2459 | } elseif ($s == '1000w2') { |
| 2460 | $ts = TsumegoUtil::collectTsumegosFromSet(216); |
| 2461 | $tsCount = count($ts); |
| 2462 | for ($i = 0; $i < $tsCount; $i++) { |
| 2463 | array_push($tsIds, $ts[$i]['Tsumego']['id']); |
| 2464 | } |
| 2465 | $uts = $this->TsumegoStatus->find('all', [ |
| 2466 | 'conditions' => [ |
| 2467 | 'user_id' => Auth::getUserID(), |
| 2468 | 'tsumego_id' => $tsIds, |
| 2469 | ], |
| 2470 | ]); |
| 2471 | if (!$uts) { |
| 2472 | $uts = []; |
| 2473 | } |
| 2474 | $counter = 0; |
| 2475 | $utsCount = count($uts); |
| 2476 | for ($j = 0; $j < $utsCount; $j++) { |
| 2477 | for ($k = 0; $k < $tsCount; $k++) { |
| 2478 | if ($uts[$j]['TsumegoStatus']['tsumego_id'] == $ts[$k]['Tsumego']['id'] && ($uts[$j]['TsumegoStatus']['status'] == 'S' |
| 2479 | || $uts[$j]['TsumegoStatus']['status'] == 'W' || $uts[$j]['TsumegoStatus']['status'] == 'C')) { |
| 2480 | $counter++; |
| 2481 | } |
| 2482 | } |
| 2483 | } |
| 2484 | if ($counter == count($ts)) { |
| 2485 | $completed = $s; |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | $achievementId = 92; |
| 2490 | if ($completed == 'cc1' && !isset($existingAs[$achievementId])) { |
| 2491 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2492 | ClassRegistry::init('AchievementStatus')->create(); |
| 2493 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2494 | array_push($updated, $achievementId); |
| 2495 | } |
| 2496 | $achievementId = 93; |
| 2497 | if ($completed == 'cc2' && !isset($existingAs[$achievementId])) { |
| 2498 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2499 | ClassRegistry::init('AchievementStatus')->create(); |
| 2500 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2501 | array_push($updated, $achievementId); |
| 2502 | } |
| 2503 | $achievementId = 94; |
| 2504 | if ($completed == 'cc3' && !isset($existingAs[$achievementId])) { |
| 2505 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2506 | ClassRegistry::init('AchievementStatus')->create(); |
| 2507 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2508 | array_push($updated, $achievementId); |
| 2509 | } |
| 2510 | $achievementId = 95; |
| 2511 | if ($completed == '1000w1' && !isset($existingAs[$achievementId])) { |
| 2512 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2513 | ClassRegistry::init('AchievementStatus')->create(); |
| 2514 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2515 | array_push($updated, $achievementId); |
| 2516 | } |
| 2517 | $achievementId = 115; |
| 2518 | if ($completed == '1000w2' && !isset($existingAs[$achievementId])) { |
| 2519 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2520 | ClassRegistry::init('AchievementStatus')->create(); |
| 2521 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2522 | array_push($updated, $achievementId); |
| 2523 | } |
| 2524 | $updatedCount = count($updated); |
| 2525 | for ($i = 0; $i < $updatedCount; $i++) { |
| 2526 | $a = ClassRegistry::init('Achievement')->findById($updated[$i]); |
| 2527 | $updated[$i] = []; |
| 2528 | $updated[$i][0] = $a['Achievement']['name']; |
| 2529 | $updated[$i][1] = $a['Achievement']['description']; |
| 2530 | $updated[$i][2] = $a['Achievement']['image']; |
| 2531 | $updated[$i][3] = $a['Achievement']['color']; |
| 2532 | $updated[$i][4] = $a['Achievement']['xp']; |
| 2533 | $updated[$i][5] = $a['Achievement']['id']; |
| 2534 | } |
| 2535 | |
| 2536 | return $updated; |
| 2537 | } |
| 2538 | |
| 2539 | protected function checkSetAchievements($sid = null) { |
| 2540 | $this->loadModel('Set'); |
| 2541 | $this->loadModel('Tsumego'); |
| 2542 | $this->loadModel('Achievement'); |
| 2543 | $this->loadModel('AchievementStatus'); |
| 2544 | $this->loadModel('AchievementCondition'); |
| 2545 | |
| 2546 | //$tNum = count($this->Tsumego->find('all', array('conditions' => array('set_id' => $sid)))); |
| 2547 | $tNum = count(TsumegoUtil::collectTsumegosFromSet($sid)); |
| 2548 | $s = $this->Set->findById($sid); |
| 2549 | $acA = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 2550 | 'order' => 'value DESC', |
| 2551 | 'conditions' => [ |
| 2552 | 'set_id' => $sid, |
| 2553 | 'user_id' => Auth::getUserID(), |
| 2554 | 'category' => '%', |
| 2555 | ], |
| 2556 | ]); |
| 2557 | if (!$acA) { |
| 2558 | return []; |
| 2559 | } |
| 2560 | $acS = ClassRegistry::init('AchievementCondition')->find('first', [ |
| 2561 | 'order' => 'value ASC', |
| 2562 | 'conditions' => [ |
| 2563 | 'set_id' => $sid, |
| 2564 | 'user_id' => Auth::getUserID(), |
| 2565 | 'category' => 's', |
| 2566 | ], |
| 2567 | ]); |
| 2568 | $buffer = ClassRegistry::init('AchievementStatus')->find('all', ['conditions' => ['user_id' => Auth::getUserID()]]); |
| 2569 | if (!$buffer) { |
| 2570 | $buffer = []; |
| 2571 | } |
| 2572 | $existingAs = []; |
| 2573 | $bufferCount = count($buffer); |
| 2574 | for ($i = 0; $i < $bufferCount; $i++) { |
| 2575 | $existingAs[$buffer[$i]['AchievementStatus']['achievement_id']] = $buffer[$i]; |
| 2576 | } |
| 2577 | $as = []; |
| 2578 | $as['AchievementStatus']['user_id'] = Auth::getUserID(); |
| 2579 | $updated = []; |
| 2580 | |
| 2581 | $achievementId = 99; |
| 2582 | if ($sid == -1 && !isset($existingAs[$achievementId])) { |
| 2583 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2584 | ClassRegistry::init('AchievementStatus')->create(); |
| 2585 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2586 | array_push($updated, $achievementId); |
| 2587 | } |
| 2588 | if ($tNum >= 100) { |
| 2589 | if ($s['Set']['difficulty'] < 1300) { |
| 2590 | $achievementId = 12; |
| 2591 | if ($acA['AchievementCondition']['value'] >= 75 && !isset($existingAs[$achievementId])) { |
| 2592 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2593 | ClassRegistry::init('AchievementStatus')->create(); |
| 2594 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2595 | array_push($updated, $achievementId); |
| 2596 | } |
| 2597 | $achievementId = 13; |
| 2598 | if ($acA['AchievementCondition']['value'] >= 85 && !isset($existingAs[$achievementId])) { |
| 2599 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2600 | ClassRegistry::init('AchievementStatus')->create(); |
| 2601 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2602 | array_push($updated, $achievementId); |
| 2603 | } |
| 2604 | $achievementId = 14; |
| 2605 | if ($acA['AchievementCondition']['value'] >= 95 && !isset($existingAs[$achievementId])) { |
| 2606 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2607 | ClassRegistry::init('AchievementStatus')->create(); |
| 2608 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2609 | array_push($updated, $achievementId); |
| 2610 | } |
| 2611 | $achievementId = 24; |
| 2612 | if ($acS['AchievementCondition']['value'] < 15 && !isset($existingAs[$achievementId])) { |
| 2613 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2614 | ClassRegistry::init('AchievementStatus')->create(); |
| 2615 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2616 | array_push($updated, $achievementId); |
| 2617 | } |
| 2618 | $achievementId = 25; |
| 2619 | if ($acS['AchievementCondition']['value'] < 10 && !isset($existingAs[$achievementId])) { |
| 2620 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2621 | ClassRegistry::init('AchievementStatus')->create(); |
| 2622 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2623 | array_push($updated, $achievementId); |
| 2624 | } |
| 2625 | $achievementId = 26; |
| 2626 | if ($acS['AchievementCondition']['value'] < 5 && !isset($existingAs[$achievementId])) { |
| 2627 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2628 | ClassRegistry::init('AchievementStatus')->create(); |
| 2629 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2630 | array_push($updated, $achievementId); |
| 2631 | } |
| 2632 | } elseif ($s['Set']['difficulty'] >= 1300 && $s['Set']['difficulty'] < 1500) { |
| 2633 | $achievementId = 15; |
| 2634 | if ($acA['AchievementCondition']['value'] >= 75 && !isset($existingAs[$achievementId])) { |
| 2635 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2636 | ClassRegistry::init('AchievementStatus')->create(); |
| 2637 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2638 | array_push($updated, $achievementId); |
| 2639 | } |
| 2640 | $achievementId = 16; |
| 2641 | if ($acA['AchievementCondition']['value'] >= 85 && !isset($existingAs[$achievementId])) { |
| 2642 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2643 | ClassRegistry::init('AchievementStatus')->create(); |
| 2644 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2645 | array_push($updated, $achievementId); |
| 2646 | } |
| 2647 | $achievementId = 17; |
| 2648 | if ($acA['AchievementCondition']['value'] >= 95 && !isset($existingAs[$achievementId])) { |
| 2649 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2650 | ClassRegistry::init('AchievementStatus')->create(); |
| 2651 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2652 | array_push($updated, $achievementId); |
| 2653 | } |
| 2654 | $achievementId = 27; |
| 2655 | if ($acS['AchievementCondition']['value'] < 18 && !isset($existingAs[$achievementId])) { |
| 2656 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2657 | ClassRegistry::init('AchievementStatus')->create(); |
| 2658 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2659 | array_push($updated, $achievementId); |
| 2660 | } |
| 2661 | $achievementId = 28; |
| 2662 | if ($acS['AchievementCondition']['value'] < 13 && !isset($existingAs[$achievementId])) { |
| 2663 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2664 | ClassRegistry::init('AchievementStatus')->create(); |
| 2665 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2666 | array_push($updated, $achievementId); |
| 2667 | } |
| 2668 | $achievementId = 29; |
| 2669 | if ($acS['AchievementCondition']['value'] < 8 && !isset($existingAs[$achievementId])) { |
| 2670 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2671 | ClassRegistry::init('AchievementStatus')->create(); |
| 2672 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2673 | array_push($updated, $achievementId); |
| 2674 | } |
| 2675 | } elseif ($s['Set']['difficulty'] >= 1500 && $s['Set']['difficulty'] < 1700) { |
| 2676 | $achievementId = 18; |
| 2677 | if ($acA['AchievementCondition']['value'] >= 75 && !isset($existingAs[$achievementId])) { |
| 2678 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2679 | ClassRegistry::init('AchievementStatus')->create(); |
| 2680 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2681 | array_push($updated, $achievementId); |
| 2682 | } |
| 2683 | $achievementId = 19; |
| 2684 | if ($acA['AchievementCondition']['value'] >= 85 && !isset($existingAs[$achievementId])) { |
| 2685 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2686 | ClassRegistry::init('AchievementStatus')->create(); |
| 2687 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2688 | array_push($updated, $achievementId); |
| 2689 | } |
| 2690 | $achievementId = 20; |
| 2691 | if ($acA['AchievementCondition']['value'] >= 95 && !isset($existingAs[$achievementId])) { |
| 2692 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2693 | ClassRegistry::init('AchievementStatus')->create(); |
| 2694 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2695 | array_push($updated, $achievementId); |
| 2696 | } |
| 2697 | $achievementId = 30; |
| 2698 | if ($acS['AchievementCondition']['value'] < 30 && !isset($existingAs[$achievementId])) { |
| 2699 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2700 | ClassRegistry::init('AchievementStatus')->create(); |
| 2701 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2702 | array_push($updated, $achievementId); |
| 2703 | } |
| 2704 | $achievementId = 31; |
| 2705 | if ($acS['AchievementCondition']['value'] < 20 && !isset($existingAs[$achievementId])) { |
| 2706 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2707 | ClassRegistry::init('AchievementStatus')->create(); |
| 2708 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2709 | array_push($updated, $achievementId); |
| 2710 | } |
| 2711 | $achievementId = 32; |
| 2712 | if ($acS['AchievementCondition']['value'] < 10 && !isset($existingAs[$achievementId])) { |
| 2713 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2714 | ClassRegistry::init('AchievementStatus')->create(); |
| 2715 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2716 | array_push($updated, $achievementId); |
| 2717 | } |
| 2718 | } else { |
| 2719 | $achievementId = 21; |
| 2720 | if ($acA['AchievementCondition']['value'] >= 75 && !isset($existingAs[$achievementId])) { |
| 2721 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2722 | ClassRegistry::init('AchievementStatus')->create(); |
| 2723 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2724 | array_push($updated, $achievementId); |
| 2725 | } |
| 2726 | $achievementId = 22; |
| 2727 | if ($acA['AchievementCondition']['value'] >= 85 && !isset($existingAs[$achievementId])) { |
| 2728 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2729 | ClassRegistry::init('AchievementStatus')->create(); |
| 2730 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2731 | array_push($updated, $achievementId); |
| 2732 | } |
| 2733 | $achievementId = 23; |
| 2734 | if ($acA['AchievementCondition']['value'] >= 95 && !isset($existingAs[$achievementId])) { |
| 2735 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2736 | ClassRegistry::init('AchievementStatus')->create(); |
| 2737 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2738 | array_push($updated, $achievementId); |
| 2739 | } |
| 2740 | $achievementId = 33; |
| 2741 | if ($acS['AchievementCondition']['value'] < 30 && !isset($existingAs[$achievementId])) { |
| 2742 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2743 | ClassRegistry::init('AchievementStatus')->create(); |
| 2744 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2745 | array_push($updated, $achievementId); |
| 2746 | } |
| 2747 | $achievementId = 34; |
| 2748 | if ($acS['AchievementCondition']['value'] < 20 && !isset($existingAs[$achievementId])) { |
| 2749 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2750 | ClassRegistry::init('AchievementStatus')->create(); |
| 2751 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2752 | array_push($updated, $achievementId); |
| 2753 | } |
| 2754 | $achievementId = 35; |
| 2755 | if ($acS['AchievementCondition']['value'] < 10 && !isset($existingAs[$achievementId])) { |
| 2756 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2757 | ClassRegistry::init('AchievementStatus')->create(); |
| 2758 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2759 | array_push($updated, $achievementId); |
| 2760 | } |
| 2761 | } |
| 2762 | $achievementId = 46; |
| 2763 | if ($acA['AchievementCondition']['value'] >= 100) { |
| 2764 | $ac100 = ClassRegistry::init('AchievementCondition')->find('all', ['conditions' => ['user_id' => Auth::getUserID(), 'category' => '%', 'value >=' => 100]]); |
| 2765 | if (!$ac100) { |
| 2766 | $ac100 = []; |
| 2767 | } |
| 2768 | $ac100counter = 0; |
| 2769 | $ac100Count = count($ac100); |
| 2770 | for ($j = 0; $j < $ac100Count; $j++) { |
| 2771 | if (count(TsumegoUtil::collectTsumegosFromSet($ac100[$j]['AchievementCondition']['set_id'])) >= 100) { |
| 2772 | $ac100counter++; |
| 2773 | } |
| 2774 | } |
| 2775 | $as100 = ClassRegistry::init('AchievementStatus')->find('first', ['conditions' => ['user_id' => Auth::getUserID(), 'achievement_id' => $achievementId]]); |
| 2776 | if ($as100 == null) { |
| 2777 | $as['AchievementStatus']['achievement_id'] = $achievementId; |
| 2778 | $as['AchievementStatus']['value'] = 1; |
| 2779 | ClassRegistry::init('AchievementStatus')->create(); |
| 2780 | ClassRegistry::init('AchievementStatus')->save($as); |
| 2781 | array_push($updated, $achievementId); |
| 2782 | } elseif ($as100['AchievementStatus']['value'] != $ac100counter) { |
| 2783 | $as100['AchievementStatus']['value'] = $ac100counter; |
| 2784 | ClassRegistry::init('AchievementStatus')->save($as100); |
| 2785 | array_push($updated, $achievementId); |
| 2786 | } |
| 2787 | } |
| 2788 | } |
| 2789 | $updatedCount = count($updated); |
| 2790 | for ($i = 0; $i < $updatedCount; $i++) { |
| 2791 | $a = ClassRegistry::init('Achievement')->findById($updated[$i]); |
| 2792 | $updated[$i] = []; |
| 2793 | $updated[$i][0] = $a['Achievement']['name']; |
| 2794 | $updated[$i][1] = $a['Achievement']['description']; |
| 2795 | $updated[$i][2] = $a['Achievement']['image']; |
| 2796 | $updated[$i][3] = $a['Achievement']['color']; |
| 2797 | $updated[$i][4] = $a['Achievement']['xp']; |
| 2798 | $updated[$i][5] = $a['Achievement']['id']; |
| 2799 | } |
| 2800 | |
| 2801 | return $updated; |
| 2802 | } |
| 2803 | |
| 2804 | public static function getXPJump($lvl = null): int { |
| 2805 | if ($lvl >= 102) { |
| 2806 | return 0; |
| 2807 | } |
| 2808 | if ($lvl == 101) { |
| 2809 | return 1150; |
| 2810 | } |
| 2811 | if ($lvl == 100) { |
| 2812 | return 50000; |
| 2813 | } |
| 2814 | if ($lvl >= 70) { |
| 2815 | return 150; |
| 2816 | } |
| 2817 | if ($lvl >= 40) { |
| 2818 | return 100; |
| 2819 | } |
| 2820 | if ($lvl >= 20) { |
| 2821 | return 50; |
| 2822 | } |
| 2823 | if ($lvl >= 12) { |
| 2824 | return 25; |
| 2825 | } |
| 2826 | |
| 2827 | return 10; |
| 2828 | } |
| 2829 | |
| 2830 | public static function updateXP($userID, $achievementData): void { |
| 2831 | $xpBonus = 0; |
| 2832 | $aCount = count($achievementData); |
| 2833 | for ($i = 0; $i < $aCount; $i++) { |
| 2834 | $xpBonus += $achievementData[$i][4]; |
| 2835 | } |
| 2836 | if ($xpBonus == 0) { |
| 2837 | return; |
| 2838 | } |
| 2839 | $user = ClassRegistry::init('User')->findById($userID); |
| 2840 | $user['User']['xp'] = $xpBonus; |
| 2841 | Level::checkLevelUp($user['User']); |
| 2842 | ClassRegistry::init('User')->save($user); |
| 2843 | } |
| 2844 | |
| 2845 | public static function getPartitionRange($amountRemaining, $collectionSize, $partition) { |
| 2846 | if ($collectionSize > 0) { |
| 2847 | $amountPartitions = ceil($amountRemaining / $collectionSize); |
| 2848 | } else { |
| 2849 | return ['0', $collectionSize - 1]; |
| 2850 | } |
| 2851 | if ($collectionSize > 0 && $amountRemaining % $collectionSize == 0) { |
| 2852 | return [ $partition * $collectionSize, $partition * $collectionSize + $collectionSize - 1]; |
| 2853 | } |
| 2854 | $amountCounter = 0; |
| 2855 | $amountFrom = 0; |
| 2856 | $amountTo = $collectionSize - 1; |
| 2857 | while ($amountRemaining > $collectionSize) { |
| 2858 | if ($partition == $amountCounter) { |
| 2859 | break; |
| 2860 | } |
| 2861 | $amountRemaining -= $collectionSize; |
| 2862 | $amountCounter++; |
| 2863 | $amountFrom += $collectionSize; |
| 2864 | $amountTo += $collectionSize; |
| 2865 | } |
| 2866 | $amountTo = $amountFrom + $collectionSize - 1; |
| 2867 | if ($partition >= $amountPartitions - 1) { |
| 2868 | $amountTo = $amountFrom + $amountRemaining - 1; |
| 2869 | } |
| 2870 | $a = []; |
| 2871 | $a[0] = $amountFrom; |
| 2872 | $a[1] = $amountTo; |
| 2873 | |
| 2874 | return $a; |
| 2875 | } |
| 2876 | |
| 2877 | /** |
| 2878 | * @param int $uid User ID |
| 2879 | * @return void |
| 2880 | */ |
| 2881 | protected function handleSearchSettings($uid) { |
| 2882 | $this->loadModel('UserContribution'); |
| 2883 | $uc = $this->UserContribution->find('first', ['conditions' => ['user_id' => $uid]]); |
| 2884 | if ($uc == null) { |
| 2885 | $uc = []; |
| 2886 | $uc['UserContribution']['user_id'] = $uid; |
| 2887 | $uc['UserContribution']['added_tag'] = 0; |
| 2888 | $uc['UserContribution']['created_tag'] = 0; |
| 2889 | $uc['UserContribution']['made_proposal'] = 0; |
| 2890 | $uc['UserContribution']['reviewed'] = 0; |
| 2891 | $uc['UserContribution']['score'] = 0; |
| 2892 | $this->UserContribution->create(); |
| 2893 | $this->UserContribution->save($uc); |
| 2894 | } |
| 2895 | new TsumegoFilters(); |
| 2896 | } |
| 2897 | |
| 2898 | protected function signIn(array $user): void { |
| 2899 | Auth::init($user); |
| 2900 | $vs = $this->TsumegoStatus->find('first', ['conditions' => ['user_id' => $user['User']['id']], 'order' => 'updated DESC']); |
| 2901 | if ($vs) { |
| 2902 | $this->Session->write('lastVisit', $vs['TsumegoStatus']['tsumego_id']); |
| 2903 | } |
| 2904 | $this->Session->write('texture', $user['User']['texture']); |
| 2905 | $this->Session->write('check1', $user['User']['id']); |
| 2906 | } |
| 2907 | |
| 2908 | public function beforeFilter(): void { |
| 2909 | $this->loadModel('User'); |
| 2910 | $this->loadModel('Activate'); |
| 2911 | $this->loadModel('Tsumego'); |
| 2912 | $this->loadModel('TsumegoRatingAttempt'); |
| 2913 | $this->loadModel('Set'); |
| 2914 | $this->loadModel('TimeModeAttempt'); |
| 2915 | $this->loadModel('TsumegoStatus'); |
| 2916 | $this->loadModel('Comment'); |
| 2917 | $this->loadModel('UserBoard'); |
| 2918 | $this->loadModel('TsumegoAttempt'); |
| 2919 | $this->loadModel('AdminActivity'); |
| 2920 | $this->loadModel('Achievement'); |
| 2921 | $this->loadModel('AchievementStatus'); |
| 2922 | $this->loadModel('AchievementCondition'); |
| 2923 | $this->loadModel('SetConnection'); |
| 2924 | $this->loadModel('Tag'); |
| 2925 | $this->loadModel('TagName'); |
| 2926 | $this->loadModel('Favorite'); |
| 2927 | |
| 2928 | Auth::init(); |
| 2929 | $timeMode = new TimeMode(); |
| 2930 | |
| 2931 | $highscoreLink = 'highscore'; |
| 2932 | $lightDark = 'light'; |
| 2933 | $resetCookies = false; |
| 2934 | $levelBar = 1; |
| 2935 | $lastProfileLeft = 1; |
| 2936 | $lastProfileRight = 2; |
| 2937 | $hasFavs = false; |
| 2938 | |
| 2939 | if (Auth::isLoggedIn()) { |
| 2940 | if (isset($_COOKIE['addTag']) && $_COOKIE['addTag'] != 0 && $this->Session->read('page') != 'set') { |
| 2941 | $newAddTag = explode('-', $_COOKIE['addTag']); |
| 2942 | $tagId = $newAddTag[0]; |
| 2943 | $newTagName = $this->TagName->find('first', ['conditions' => ['name' => str_replace($tagId . '-', '', $_COOKIE['addTag'])]]); |
| 2944 | if ($newTagName) { |
| 2945 | $saveTag = []; |
| 2946 | $saveTag['Tag']['tag_name_id'] = $newTagName['TagName']['id']; |
| 2947 | $saveTag['Tag']['tsumego_id'] = $tagId; |
| 2948 | $saveTag['Tag']['user_id'] = Auth::getUserID(); |
| 2949 | $saveTag['Tag']['approved'] = 0; |
| 2950 | $this->Tag->save($saveTag); |
| 2951 | } |
| 2952 | $this->set('removeCookie', 'addTag'); |
| 2953 | } |
| 2954 | if (isset($_COOKIE['z_sess']) && $_COOKIE['z_sess'] != 0 |
| 2955 | && strlen($_COOKIE['z_sess']) > 5) { |
| 2956 | Auth::getUser()['_sessid'] = $_COOKIE['z_sess']; |
| 2957 | Auth::saveUser(); |
| 2958 | } |
| 2959 | if (Auth::getUser()['lastHighscore'] == 1) { |
| 2960 | $highscoreLink = 'highscore'; |
| 2961 | } elseif (Auth::getUser()['lastHighscore'] == 2) { |
| 2962 | $highscoreLink = 'rating'; |
| 2963 | } elseif (Auth::getUser()['lastHighscore'] == 3) { |
| 2964 | $highscoreLink = 'leaderboard'; |
| 2965 | } elseif (Auth::getUser()['lastHighscore'] == 4) { |
| 2966 | $highscoreLink = 'highscore3'; |
| 2967 | } |
| 2968 | |
| 2969 | if (isset($_COOKIE['lastMode']) && $_COOKIE['lastMode'] != 0) { |
| 2970 | Auth::getUser()['lastMode'] = $_COOKIE['lastMode']; |
| 2971 | Auth::saveUser(); |
| 2972 | } |
| 2973 | if (isset($_COOKIE['sound']) && $_COOKIE['sound'] != '0') { |
| 2974 | Auth::getUser()['sound'] = $_COOKIE['sound']; |
| 2975 | Auth::saveUser(); |
| 2976 | unset($_COOKIE['sound']); |
| 2977 | } |
| 2978 | $this->set('ac', true); |
| 2979 | $this->set('user', Auth::getUser()); |
| 2980 | } |
| 2981 | |
| 2982 | if (isset($_COOKIE['lightDark']) && $_COOKIE['lightDark'] != '0') { |
| 2983 | $lightDark = $_COOKIE['lightDark']; |
| 2984 | if (Auth::isLoggedIn()) { |
| 2985 | // Convert string to integer for database storage |
| 2986 | $lightDarkInt = ($lightDark === 'light') ? 0 : 2; |
| 2987 | Auth::getUser()['lastLight'] = $lightDarkInt; |
| 2988 | } |
| 2989 | } elseif (Auth::isLoggedIn()) { |
| 2990 | if (Auth::getUser()['lastLight'] == 0 |
| 2991 | || Auth::getUser()['lastLight'] == 1) { |
| 2992 | $lightDark = 'light'; |
| 2993 | } else { |
| 2994 | $lightDark = 'dark'; |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | if (Auth::isLoggedIn()) { |
| 2999 | $this->handleSearchSettings(Auth::getUserID()); |
| 3000 | if (isset($_COOKIE['levelBar']) && $_COOKIE['levelBar'] != '0') { |
| 3001 | $levelBar = $_COOKIE['levelBar']; |
| 3002 | Auth::getUser()['levelBar'] = $levelBar; |
| 3003 | } elseif (Auth::getUser()['levelBar'] == 0 |
| 3004 | || Auth::getUser()['levelBar'] == 'level') { |
| 3005 | $levelBar = 1; |
| 3006 | } else { |
| 3007 | $levelBar = 2; |
| 3008 | } |
| 3009 | |
| 3010 | if (isset($_COOKIE['lastProfileLeft']) && $_COOKIE['lastProfileLeft'] != '0') { |
| 3011 | $lastProfileLeft = $_COOKIE['lastProfileLeft']; |
| 3012 | Auth::getUser()['lastProfileLeft'] = $lastProfileLeft; |
| 3013 | } else { |
| 3014 | $lastProfileLeft = Auth::getUser()['lastProfileLeft']; |
| 3015 | if ($lastProfileLeft == 0) { |
| 3016 | $lastProfileLeft = 1; |
| 3017 | } |
| 3018 | } |
| 3019 | if (isset($_COOKIE['lastProfileRight']) && $_COOKIE['lastProfileRight'] != '0') { |
| 3020 | $lastProfileRight = $_COOKIE['lastProfileRight']; |
| 3021 | Auth::getUser()['lastProfileRight'] = $lastProfileRight; |
| 3022 | } else { |
| 3023 | $lastProfileRight = Auth::getUser()['lastProfileRight']; |
| 3024 | if ($lastProfileRight == 0) { |
| 3025 | $lastProfileRight = 1; |
| 3026 | } |
| 3027 | } |
| 3028 | } |
| 3029 | $mode = 1; |
| 3030 | if (isset($_COOKIE['mode']) && $_COOKIE['mode'] != '0') { |
| 3031 | if ($_COOKIE['mode'] == 1) { |
| 3032 | $mode = 1; |
| 3033 | } else { |
| 3034 | $mode = 2; |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | if (Auth::isLoggedIn() && Auth::getUser()['mode'] == 2) { |
| 3039 | $mode = 2; |
| 3040 | } |
| 3041 | |
| 3042 | if ($_COOKIE['sprint'] != 1) { |
| 3043 | $this->updateSprintCondition(); |
| 3044 | } |
| 3045 | $correctSolveAttempt = false; |
| 3046 | |
| 3047 | if (Auth::isLoggedIn()) { |
| 3048 | if (isset($_COOKIE['revelation']) && $_COOKIE['revelation'] != 0) { |
| 3049 | Auth::getUser()['revelation'] -= 1; |
| 3050 | } |
| 3051 | |
| 3052 | if (!$this->request->is('ajax')) { |
| 3053 | $this->PlayResultProcessor->checkPreviousPlay($timeMode); |
| 3054 | } |
| 3055 | |
| 3056 | if (isset($_COOKIE['noScore']) && isset($_COOKIE['noPreId'])) { |
| 3057 | if ($_COOKIE['noScore'] != '0' && $_COOKIE['noPreId'] != '0') { |
| 3058 | //$previosTsumegoX = $this->Tsumego->findById($_COOKIE['noPreId']); |
| 3059 | //$previosTsumegoXsc = $this->SetConnection->find('first', array('conditions' => array('tsumego_id' => $_COOKIE['noPreId']))); |
| 3060 | //$scoreArrX = explode('-', $this->decrypt($_COOKIE['noScore'])); |
| 3061 | |
| 3062 | $utPreX = $this->TsumegoStatus->find('first', ['conditions' => ['tsumego_id' => $_COOKIE['noPreId'], 'user_id' => Auth::getUserID()]]); |
| 3063 | if ($utPreX == null) { |
| 3064 | $utPreX['TsumegoStatus'] = []; |
| 3065 | $utPreX['TsumegoStatus']['user_id'] = Auth::getUserID(); |
| 3066 | $utPreX['TsumegoStatus']['tsumego_id'] = $_COOKIE['noPreId']; |
| 3067 | } |
| 3068 | if ($utPreX['TsumegoStatus']['status'] == 'W') { |
| 3069 | $utPreX['TsumegoStatus']['status'] = 'C'; |
| 3070 | } else { |
| 3071 | $utPreX['TsumegoStatus']['status'] = 'S'; |
| 3072 | } |
| 3073 | $utPreX['TsumegoStatus']['created'] = date('Y-m-d H:i:s'); |
| 3074 | //$this->TsumegoStatus->save($utPreX); |
| 3075 | //$sessionUts = $this->Session->read('loggedInUser.uts'); |
| 3076 | /*if (!$sessionUts) { |
| 3077 | $sessionUts = []; |
| 3078 | } |
| 3079 | $sessionUts[$utPreX['TsumegoStatus']['tsumego_id']] = $utPreX['TsumegoStatus']['status']; |
| 3080 | $this->Session->write('loggedInUser.uts', $sessionUts);*/ |
| 3081 | } |
| 3082 | } |
| 3083 | } |
| 3084 | $boardNames = []; |
| 3085 | $enabledBoards = []; |
| 3086 | $boardPositions = []; |
| 3087 | |
| 3088 | $boardNames[1] = 'Pine'; |
| 3089 | $boardNames[2] = 'Ash'; |
| 3090 | $boardNames[3] = 'Maple'; |
| 3091 | $boardNames[4] = 'Shin Kaya'; |
| 3092 | $boardNames[5] = 'Birch'; |
| 3093 | $boardNames[6] = 'Wenge'; |
| 3094 | $boardNames[7] = 'Walnut'; |
| 3095 | $boardNames[8] = 'Mahogany'; |
| 3096 | $boardNames[9] = 'Blackwood'; |
| 3097 | $boardNames[10] = 'Marble 1'; |
| 3098 | $boardNames[11] = 'Marble 2'; |
| 3099 | $boardNames[12] = 'Marble 3'; |
| 3100 | $boardNames[13] = 'Tibet Spruce'; |
| 3101 | $boardNames[14] = 'Marble 4'; |
| 3102 | $boardNames[15] = 'Marble 5'; |
| 3103 | $boardNames[16] = 'Quarry 1'; |
| 3104 | $boardNames[17] = 'Flowers'; |
| 3105 | $boardNames[18] = 'Nova'; |
| 3106 | $boardNames[19] = 'Spring'; |
| 3107 | $boardNames[20] = 'Moon'; |
| 3108 | $boardNames[21] = 'Apex'; |
| 3109 | $boardNames[22] = 'Gold 1'; |
| 3110 | $boardNames[23] = 'Amber'; |
| 3111 | $boardNames[24] = 'Marble 6'; |
| 3112 | $boardNames[25] = 'Marble 7'; |
| 3113 | $boardNames[26] = 'Marble 8'; |
| 3114 | $boardNames[27] = 'Marble 9'; |
| 3115 | $boardNames[28] = 'Marble 10'; |
| 3116 | $boardNames[29] = 'Jade'; |
| 3117 | $boardNames[30] = 'Quarry 2'; |
| 3118 | $boardNames[31] = 'Black Bricks'; |
| 3119 | $boardNames[32] = 'Wallpaper 1'; |
| 3120 | $boardNames[33] = 'Wallpaper 2'; |
| 3121 | $boardNames[34] = 'Gold & Gray'; |
| 3122 | $boardNames[35] = 'Gold & Pink'; |
| 3123 | $boardNames[36] = 'Veil'; |
| 3124 | $boardNames[37] = 'Tiles'; |
| 3125 | $boardNames[38] = 'Mars'; |
| 3126 | $boardNames[39] = 'Pink Cloud'; |
| 3127 | $boardNames[40] = 'Reptile'; |
| 3128 | $boardNames[41] = 'Mezmerizing'; |
| 3129 | $boardNames[42] = 'Magenta Sky'; |
| 3130 | $boardNames[43] = 'Tsumego Hero'; |
| 3131 | $boardNames[44] = 'Pretty'; |
| 3132 | $boardNames[45] = 'Hunting'; |
| 3133 | $boardNames[46] = 'Haunted'; |
| 3134 | $boardNames[47] = 'Carnage'; |
| 3135 | $boardNames[48] = 'Blind Spot'; |
| 3136 | $boardNames[49] = 'Giants'; |
| 3137 | $boardNames[50] = 'Gems'; |
| 3138 | $boardNames[51] = 'Grandmaster'; |
| 3139 | $boardPositions[1] = [1, 'texture1', 'black34.png', 'white34.png']; |
| 3140 | $boardPositions[2] = [2, 'texture2', 'black34.png', 'white34.png']; |
| 3141 | $boardPositions[3] = [3, 'texture3', 'black34.png', 'white34.png']; |
| 3142 | $boardPositions[4] = [4, 'texture4', 'black.png', 'white.png']; |
| 3143 | $boardPositions[5] = [5, 'texture5', 'black34.png', 'white34.png']; |
| 3144 | $boardPositions[6] = [6, 'texture6', 'black.png', 'white.png']; |
| 3145 | $boardPositions[7] = [7, 'texture7', 'black34.png', 'white34.png']; |
| 3146 | $boardPositions[8] = [8, 'texture8', 'black.png', 'white.png']; |
| 3147 | $boardPositions[9] = [9, 'texture9', 'black.png', 'white.png']; |
| 3148 | $boardPositions[10] = [10, 'texture10', 'black34.png', 'white34.png']; |
| 3149 | $boardPositions[11] = [11, 'texture11', 'black34.png', 'white34.png']; |
| 3150 | $boardPositions[12] = [12, 'texture12', 'black34.png', 'white34.png']; |
| 3151 | $boardPositions[13] = [13, 'texture13', 'black34.png', 'white34.png']; |
| 3152 | $boardPositions[14] = [14, 'texture14', 'black34.png', 'white34.png']; |
| 3153 | $boardPositions[15] = [15, 'texture15', 'black.png', 'white.png']; |
| 3154 | $boardPositions[16] = [16, 'texture16', 'black34.png', 'white34.png']; |
| 3155 | $boardPositions[17] = [17, 'texture17', 'black34.png', 'white34.png']; |
| 3156 | $boardPositions[18] = [18, 'texture18', 'black.png', 'white.png']; |
| 3157 | $boardPositions[19] = [19, 'texture19', 'black34.png', 'white34.png']; |
| 3158 | $boardPositions[20] = [20, 'texture20', 'black34.png', 'white34.png']; |
| 3159 | $boardPositions[21] = [33, 'texture33', 'black34.png', 'white34.png']; |
| 3160 | $boardPositions[22] = [21, 'texture21', 'black.png', 'whiteKo.png']; |
| 3161 | $boardPositions[23] = [22, 'texture22', 'black34.png', 'white34.png']; |
| 3162 | $boardPositions[24] = [34, 'texture34', 'black.png', 'white.png']; |
| 3163 | $boardPositions[25] = [35, 'texture35', 'black34.png', 'white34.png']; |
| 3164 | $boardPositions[26] = [36, 'texture36', 'black.png', 'white.png']; |
| 3165 | $boardPositions[27] = [37, 'texture37', 'black34.png', 'white34.png']; |
| 3166 | $boardPositions[28] = [38, 'texture38', 'black38.png', 'white34.png']; |
| 3167 | $boardPositions[29] = [39, 'texture39', 'black.png', 'white.png']; |
| 3168 | $boardPositions[30] = [40, 'texture40', 'black34.png', 'white34.png']; |
| 3169 | $boardPositions[31] = [41, 'texture41', 'black34.png', 'white34.png']; |
| 3170 | $boardPositions[32] = [42, 'texture42', 'black34.png', 'white42.png']; |
| 3171 | $boardPositions[33] = [43, 'texture43', 'black34.png', 'white42.png']; |
| 3172 | $boardPositions[34] = [44, 'texture44', 'black34.png', 'white34.png']; |
| 3173 | $boardPositions[35] = [45, 'texture45', 'black34.png', 'white42.png']; |
| 3174 | $boardPositions[36] = [47, 'texture47', 'black34.png', 'white34.png']; |
| 3175 | $boardPositions[37] = [48, 'texture48', 'black34.png', 'white34.png']; |
| 3176 | $boardPositions[38] = [49, 'texture49', 'black.png', 'white.png']; |
| 3177 | $boardPositions[39] = [50, 'texture50', 'black34.png', 'white34.png']; |
| 3178 | $boardPositions[40] = [51, 'texture51', 'black34.png', 'white34.png']; |
| 3179 | $boardPositions[41] = [52, 'texture52', 'black34.png', 'white34.png']; |
| 3180 | $boardPositions[42] = [53, 'texture53', 'black34.png', 'white34.png']; |
| 3181 | $boardPositions[43] = [54, 'texture54', 'black54.png', 'white54.png']; |
| 3182 | $boardPositions[44] = [23, 'texture23', 'black.png', 'whiteFlower.png']; |
| 3183 | $boardPositions[45] = [24, 'texture24', 'black24.png', 'white24.png']; |
| 3184 | $boardPositions[46] = [25, 'texture25', 'blackGhost.png', 'white.png']; |
| 3185 | $boardPositions[47] = [26, 'texture26', 'blackInvis.png', 'whiteCarnage.png']; |
| 3186 | $boardPositions[48] = [27, 'texture27', 'black27.png', 'white27.png']; |
| 3187 | $boardPositions[49] = [28, 'texture28', 'blackGiant.png', 'whiteKo.png']; |
| 3188 | $boardPositions[50] = [29, 'texture29', 'blackKo.png', 'whiteKo.png']; |
| 3189 | $boardPositions[51] = [30, 'texture55', 'blackGalaxy.png', 'whiteGalaxy.png']; |
| 3190 | |
| 3191 | $boardCount = 51; |
| 3192 | |
| 3193 | if ($this->Session->check('texture') || (isset($_COOKIE['texture']) && $_COOKIE['texture'] != '0')) { |
| 3194 | $splitCookie = []; |
| 3195 | if (isset($_COOKIE['texture']) && $_COOKIE['texture'] != '0') { |
| 3196 | $splitCookie = str_split($_COOKIE['texture']); |
| 3197 | $textureCookies = $_COOKIE['texture']; |
| 3198 | Auth::getUser()['texture'] = $this->Session->read('texture'); |
| 3199 | $this->Session->write('texture', $_COOKIE['texture']); |
| 3200 | $this->set('textureCookies', $textureCookies); |
| 3201 | } else { |
| 3202 | if (Auth::isLoggedIn()) { |
| 3203 | $this->Session->write('texture', Auth::getUser()['texture']); |
| 3204 | } |
| 3205 | $textureCookies = $this->Session->read('texture'); |
| 3206 | $splitTextureCookies = str_split($textureCookies); |
| 3207 | $splitTextureCookiesCount = count($splitTextureCookies); |
| 3208 | for ($i = 0; $i < $splitTextureCookiesCount; $i++) { |
| 3209 | if ($splitTextureCookies[$i] == 2) { |
| 3210 | $enabledBoards[$i + 1] = 'checked'; |
| 3211 | } else { |
| 3212 | $enabledBoards[$i + 1] = ''; |
| 3213 | } |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | $splitCookieCount = count($splitCookie); |
| 3218 | for ($i = 0; $i < $splitCookieCount; $i++) { |
| 3219 | if ($splitCookie[$i] == 2) { |
| 3220 | $enabledBoards[$i + 1] = 'checked'; |
| 3221 | } else { |
| 3222 | $enabledBoards[$i + 1] = ''; |
| 3223 | } |
| 3224 | } |
| 3225 | if (Auth::isLoggedIn()) { |
| 3226 | Auth::saveUser(); |
| 3227 | } |
| 3228 | } |
| 3229 | |
| 3230 | if (!$this->Session->check('texture')) { |
| 3231 | $this->Session->write('texture', '222222221111111111111111111111111111111111111111111'); |
| 3232 | $enabledBoards[1] = 'checked'; |
| 3233 | $enabledBoards[2] = 'checked'; |
| 3234 | $enabledBoards[3] = 'checked'; |
| 3235 | $enabledBoards[4] = 'checked'; |
| 3236 | $enabledBoards[5] = 'checked'; |
| 3237 | $enabledBoards[6] = 'checked'; |
| 3238 | $enabledBoards[7] = 'checked'; |
| 3239 | $enabledBoards[8] = 'checked'; |
| 3240 | $enabledBoards[9] = ''; |
| 3241 | $enabledBoards[10] = ''; |
| 3242 | $enabledBoards[11] = ''; |
| 3243 | $enabledBoards[12] = ''; |
| 3244 | $enabledBoards[13] = ''; |
| 3245 | $enabledBoards[14] = ''; |
| 3246 | $enabledBoards[15] = ''; |
| 3247 | $enabledBoards[16] = ''; |
| 3248 | $enabledBoards[17] = ''; |
| 3249 | $enabledBoards[18] = ''; |
| 3250 | $enabledBoards[19] = ''; |
| 3251 | $enabledBoards[20] = ''; |
| 3252 | $enabledBoards[21] = ''; |
| 3253 | $enabledBoards[22] = ''; |
| 3254 | $enabledBoards[23] = ''; |
| 3255 | $enabledBoards[24] = ''; |
| 3256 | $enabledBoards[25] = ''; |
| 3257 | $enabledBoards[26] = ''; |
| 3258 | $enabledBoards[27] = ''; |
| 3259 | $enabledBoards[28] = ''; |
| 3260 | $enabledBoards[29] = ''; |
| 3261 | $enabledBoards[30] = ''; |
| 3262 | $enabledBoards[31] = ''; |
| 3263 | $enabledBoards[32] = ''; |
| 3264 | $enabledBoards[33] = ''; |
| 3265 | $enabledBoards[34] = ''; |
| 3266 | $enabledBoards[35] = ''; |
| 3267 | $enabledBoards[36] = ''; |
| 3268 | $enabledBoards[37] = ''; |
| 3269 | $enabledBoards[38] = ''; |
| 3270 | $enabledBoards[39] = ''; |
| 3271 | $enabledBoards[40] = ''; |
| 3272 | $enabledBoards[41] = ''; |
| 3273 | $enabledBoards[42] = ''; |
| 3274 | $enabledBoards[43] = ''; |
| 3275 | $enabledBoards[44] = ''; |
| 3276 | $enabledBoards[45] = ''; |
| 3277 | $enabledBoards[46] = ''; |
| 3278 | $enabledBoards[47] = ''; |
| 3279 | $enabledBoards[48] = ''; |
| 3280 | $enabledBoards[49] = ''; |
| 3281 | $enabledBoards[50] = ''; |
| 3282 | $enabledBoards[51] = ''; |
| 3283 | } |
| 3284 | $achievementUpdate = []; |
| 3285 | if ($this->Session->check('initialLoading')) { |
| 3286 | $achievementUpdate1 = $this->checkLevelAchievements(); |
| 3287 | $achievementUpdate2 = $this->checkProblemNumberAchievements(); |
| 3288 | $achievementUpdate3 = $this->checkRatingAchievements(); |
| 3289 | $achievementUpdate4 = $this->checkTimeModeAchievements(); |
| 3290 | $achievementUpdate5 = $this->checkDanSolveAchievements(); |
| 3291 | $achievementUpdate = array_merge( |
| 3292 | $achievementUpdate1 ?: [], |
| 3293 | $achievementUpdate2 ?: [], |
| 3294 | $achievementUpdate3 ?: [], |
| 3295 | $achievementUpdate4 ?: [], |
| 3296 | $achievementUpdate5 ?: [] |
| 3297 | ); |
| 3298 | $this->Session->delete('initialLoading'); |
| 3299 | } |
| 3300 | |
| 3301 | if (count($achievementUpdate) > 0) { |
| 3302 | $this->updateXP(Auth::getUserID(), $achievementUpdate); |
| 3303 | } |
| 3304 | |
| 3305 | $nextDay = new DateTime('tomorrow'); |
| 3306 | if (Auth::isLoggedIn()) { |
| 3307 | Auth::getUser()['name'] = $this->checkPicture(Auth::getUser()); |
| 3308 | $this->set('user', Auth::getUser()); |
| 3309 | } |
| 3310 | $this->set('mode', $mode); |
| 3311 | $this->set('nextDay', $nextDay->format('m/d/Y')); |
| 3312 | $this->set('boardNames', $boardNames); |
| 3313 | $this->set('enabledBoards', $enabledBoards); |
| 3314 | $this->set('boardPositions', $boardPositions); |
| 3315 | $this->set('highscoreLink', $highscoreLink); |
| 3316 | $this->set('achievementUpdate', $achievementUpdate); |
| 3317 | $this->set('lightDark', $lightDark); |
| 3318 | $this->set('levelBar', $levelBar); |
| 3319 | $this->set('lastProfileLeft', $lastProfileLeft); |
| 3320 | $this->set('lastProfileRight', $lastProfileRight); |
| 3321 | $this->set('resetCookies', $resetCookies); |
| 3322 | $this->set('hasFavs', $hasFavs); |
| 3323 | } |
| 3324 | |
| 3325 | public function afterFilter() {} |
| 3326 | } |